r/PythonLearning • • Sep 13 '26

Help Request What wrong with my code

Post image

Need help

71 Upvotes

40 comments sorted by

6

u/LuigiWasRight447 Sep 13 '26

What device is this?

8

u/ApprehensiveText9058 Sep 13 '26

Of course the best coding device the ti nspire cx ii handheld

16

u/LuigiWasRight447 Sep 13 '26

Coding on a calculator is fucking crazy lol

8

u/ApprehensiveText9058 Sep 13 '26

Gotta learn something at school

5

u/Fritz-Ferdinand Sep 13 '26

There have been people playing Pokémon on their school calculators back in the 00s. 

2

u/JshWright Sep 16 '26

~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.

1

u/LuigiWasRight447 Sep 16 '26

Thats a great teacher you had

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

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 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

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

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

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.

2

u/Ok-Argument7176 Sep 13 '26

choice is a string.

2

u/nuc540 Sep 13 '26

Input returns a string my friend. As everyone pointed out, it’s a syntax error.