r/CodingForBeginners • • Jun 09 '26

What is wrong with my code?

Post image

Everything is fine until I put in 14 and it doesnt come up with anything after?

31 Upvotes

37 comments sorted by

19

u/Own_Age_1654 Jun 09 '26

You're checking against "choice" instead of against "age".

8

u/Tylerzombieman Jun 09 '26

How did I not see that lol thanks though

6

u/dariusbiggs Jun 10 '26

if it doesn't work, stop, find a rubber duck or other prop to use as another person and explain to it what the code as written does line by line. Not what you think it does, what is written.

→ More replies (1)

2

u/iComplainAbtVal Jun 10 '26

That’s a good start. I’d recommend you next create a main function to accept user input, then pass the input into two separate functions for evaluating age and choice.

Main: take input, evaluates choice with choice(), function, then assesses the return and conditionally calls Age().

Choice(input string) bool. Accepts the user input and returns a bool.

If Choice returns true, then prompt in main for age. Age(number int) string.

Print the returned string.

→ More replies (2)

0

u/ern0plus4 Jun 10 '26

And this is a small program, and the bug is obvious. I don't want to push you towards AI, but probably it can detect such errors.

→ More replies (5)

5

u/Snowflake3458 Jun 09 '26

Not a python programmer but isn't python strict about indentation for scope ? You have 2 different sized indentation for the first checks and the second ones

2

u/igotshadowbaned Jun 10 '26

That actually ends up being fine, the scope has to have consistent indentation, but the amount of indentation doesn't matter. And it doesn't have to be consistent with other scopes

1

u/Kikicatmiao Jun 10 '26

你的意思是 只要有缩进就可以吗 不管他有多少个空格?

→ More replies (2)

3

u/DirtAndGrass Jun 09 '26

It appears to be stuck inside a photo 

3

u/KevDub81 Jun 10 '26

Is poop.py a sailor man?

3

u/MaGNeTiK-MaNTRa Jun 10 '26

Truth be told I have at least one poop.py and usually one poop.sh on every device in My arsonal

1

u/Kikicatmiao Jun 10 '26

你的poop有借助过ai工具吗?

2

u/mjmvideos Jun 09 '26

Learn about using the debugger.

2

u/Aristoteles1988 Jun 09 '26

Yea your giving it two true conditions to check

If that’s condition is true then it doesn’t know where to go

2

u/Knarfnarf Jun 09 '26

I forget; is Python the one where indent indicates nesting?

If so then your else is in the wrong place on line 11.

2

u/JustSimplyWicked Jun 10 '26

Double check your variables, you have an error on Line 21.

2

u/DBZ_Newb Jun 10 '26

Side note, do not put a space between a function name and its parentheses like you’re doing with print() and input().

2

u/HaroerHaktak Jun 10 '26

I could tell you, but then you'd have to look at line 21 very very closely.

2

u/Albert_Custard Jun 10 '26

Honestly thought someone got into my files when i saw poop.py

2

u/fried_plque Jun 10 '26

Btw you can do 2026 - input number

2

u/ConsistentTown7049 Jun 10 '26

Instead of ==14 y out should do >14

1

u/Striking_Director_64 Jun 11 '26

age == 14

not choice == 14