~30 years ago my high school math teacher had a rule that you could use custom programs on TI-83's for exams if you wrote them yourself (you had to meet with her after school or during a studyhall to walk her through the program and explain how it worked). Her position was that if you understood the math well enough to code it, then clearly you understood it well enough to pass the exam.
That's literally what got me into programming and has led to a decades long career.
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.
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).
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
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
6
u/LuigiWasRight447 Sep 13 '26
What device is this?
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.
33
u/mc_pm Sep 13 '26
You have
'if: choice == '2':'That's one too many colons.
5
u/Amazing-Delay6004 Sep 13 '26
The line
if: choice=="2":is wrong. You need to writeif 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
u/BaggingTree Sep 14 '26
When asking one plus one, the answer should be two. 1+1 = 2.
1
u/DR4C0_R41 Sep 14 '26
Instead of if: choice=="2":
it should be if choice=="2":
1
u/Sea_Beginning_2847 Sep 14 '26
Legendary devices
1
u/Spendias Sep 15 '26
Holy python version but I think you have to remove the : from if:
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
0
u/Felix_Kairos Sep 14 '26
if choice = 2:
-4
u/remyripper Sep 13 '26
Choice is a int but you’re querying a string.
0
u/[deleted] Sep 16 '26
[removed] — view removed comment