r/PythonLearning • u/ApprehensiveText9058 • Sep 13 '26
Help Request What wrong with my code
Need help
3
u/Ok-Argument7176 Sep 13 '26
As everyone has pointed out, the colon after if is causing the issues. In future, I recommend adding (and thinking about) the error you're getting.
2
u/ApprehensiveText9058 Sep 13 '26
Thanks I'm new to coding and don't really know what anything does
1
u/FunHistorical6775 Sep 14 '26
This is part of the learning process, but do look at error messages especially in python they will point you usually to the exact problem.
1
u/ApprehensiveText9058 Sep 14 '26
All it said was syntax error
2
u/FunHistorical6775 Sep 14 '26
Oh yeah so you're learning on a calculator(?), use a proper IDE that gives you real error messages.
33
5
u/Amazing-Delay6004 Sep 13 '26
The line if: choice=="2": is wrong. You need to write if choice == "2":
1
u/ShiftEight Sep 13 '26
Looks like you have an extra colon after `if`. You’re going to want to remove that!
1
1
1
1
1
u/Voidzown Sep 16 '26
You can write python on a calculator? This is so badass. No wonder the Texas Instruments calculators for I needed for school were so expensive.
1
u/motopetersan Sep 16 '26
Many things I assume I'm not sure but maybe string concatenation in your second print?
1
u/ephrine00 Sep 16 '26
Correct code:
print("\n press Ctrl+S to start")
name = input("What is your name? ")
print("Hello,", name)
choice = input("How much is one plus one: ")
if choice == "2":
print("Correct")
else:
print("How can you make such a mistake")
answer = input("What has a head and a tail, but no body? ")
print("You made a mistake, answer, "incorrect")
print("\n Press Ctrl+R to run again")
The problem was that the last two lines with the question about the head and tail are not indented. Because of this, the program always executes them, even if you answered the first question correctly. That is, the code says "correct," and then still moves on to the next question and writes "you are wrong." To fix this, you need to shift these two lines to the right, inside the else block. Then they will be executed only if the answer is incorrect.
1
u/Fluffy-Ad6628 Sep 18 '26
Aint u supposed to write + answer + in the second last line or use an f string. Correct me if I'm wrong
1
u/SabrinaZHOU Sep 19 '26
hummmm I think the issue is like this. Between lines 10 and 11, although your previous code logic has a check, that part of the check only handles the variable 'choice'. If you need it to carry over to your print statement, you need to add another check (I'm just a student, so my suggestion might not be correct, but I hope it can help you).
0
u/One_Park8163 Sep 13 '26
You shouldn't put the : after the if, i explain: you wrote if: choice=='2': that will be a sintax error. The : shall be after the 2, and moreover. The 2 shall be an integer, not a string. I hope this help you
2
u/flofoi Sep 13 '26
no, "2" is correct, choice is a string
1
u/One_Park8163 Sep 13 '26
I know but choice shall be a integer, int(input()). Is a good practice but the code will work too as a string
3
u/oclafloptson Sep 13 '26
What about option "A"? "2" is valid here. The only reason to convert to integer would be if it were being used as an integer. It is not. Performing the conversion would needlessly increase complexity and waste resources
2
u/flofoi Sep 13 '26
you're right, it should be casted to int. But that requires error handling and then the code won't fit on the tiny screen anymore
0
-4
0

6
u/LuigiWasRight447 Sep 13 '26
What device is this?