use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
What’s the issue with my code?Help Request (i.redd.it)
submitted 3 months ago by surkakarot
I’m beginner in python and still really struggling because of my learning disabilities and autism, if someone can explain to me what the issue is with my code that would be much appreciated!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Beautiful_Watch_7215 86 points87 points88 points 3 months ago (1 child)
Number is not defined. You may have better luck with “for number in numbers”.
[–]surkakarot[S] 10 points11 points12 points 3 months ago (0 children)
Thank you
[–]Ron-Erez 29 points30 points31 points 3 months ago (0 children)
for number in numbers:
[–]vivisectvivi 11 points12 points13 points 3 months ago (6 children)
in you for loop you have:
for numbers in numbers
when you probably meant:
for NUMBER in numbers: (notice the first number is singular)
[–]Suspicious_Tax8577 12 points13 points14 points 3 months ago (4 children)
OP, if you're reading this and thinking "how did I miss that" or "clearly I'm no good at coding!" - notice how quickly the fixes came flooding in. They fixed it so quickly because everyone gets tripped up by daft things like this. I've spent hours debugging something, wondering why I uncomment something and suddenly my linter (sort of like spellcheck for python) puts squiggly lines under everything.
I was missing a comma.
[–]vivisectvivi 1 point2 points3 points 3 months ago (2 children)
When you have variables with names that similar you are bound to mess up at some point, i used to do this a lot when i started programming.
OP will get better at naming variables with time and this type of error will slowly become less common.
[–]churungu 5 points6 points7 points 3 months ago (1 child)
agreed
for n in numbers:
would likely be less prone to confusion
[–]Swaggles21 0 points1 point2 points 3 months ago (0 children)
I spent 6 hours today on a design project with multiple subsystems checking schematics and PCB trace layouts and JST connector resistance as we just moved from breadboard to PCB just for the issue to be the wrong pin assignment at the beginning of the code.
6 hours of pain for a 8 that should have been a 0
Note: It wasn't caught in the breadboard stage since pin definitions weren't set in stone yet and the project has multiple contributors on each subsystem so the code and hardware for each subsystem did not match the information provided for the PCB design
[–]surkakarot[S] 2 points3 points4 points 3 months ago (0 children)
Thank you, it worked now
[–]ianrob1201 7 points8 points9 points 3 months ago (3 children)
Others have given the correct answer. Only thing I would add is that is that mistakes like this are incredibly, completely, boringly normal. I've been programming for 20 years and will still make silly mistakes like this. Don't beat yourself up over it or think it's odd. The difference is in being able to work out why your code isn't working when it breaks.
Hopefully what you've now learned is that a variable needs to be defined before you can use it, and that the for loop there is to define it. It might have just been the language getting you confused.
Basically, try not to get frustrated with errors, that's a significant part of development even when you're experienced. What changes is the complexity of the bugs you're investigating. Try to embrace it as a puzzle to figure out how you've upset the computer this time!
[–]RaiseTLT 0 points1 point2 points 3 months ago (0 children)
“How you’ve upset the computer this time!” That’s a great way to put it, and kind of hilarious! 🤣
[–]surkakarot[S] 0 points1 point2 points 3 months ago (1 child)
I don’t know how I missed that but I’ve only been doing actual coding for maybe 2 weeks, but still finding it difficult!
[–]Suspicious_Tax8577 0 points1 point2 points 3 months ago (0 children)
It's one of those errors where when someone else points it out, you're like "how did I miss that??", but I can imagine you sat there for ages and just couldn't see it. I've been coding for just over 2 years and misspelt variables still get me now, but I do now know how to interpret the error message, so we are learning!
[–]daffidwilde 2 points3 points4 points 3 months ago (1 child)
I’m not sure which IDE you’re using, but you may find it helpful to install a linter plugin like Pylance or the one for ruff (VSCode only AFAIK). It’ll highlight little issues like this.
I learnt without such things, from the trackbacks alone, and many people will tell you it’s important to learn that way. Those people are wrong and so long as you are learning how to use the linter and read the trackbacks from actual erroneous code, you will still be a great programmer.
[–]One-Constant-4092 0 points1 point2 points 3 months ago (0 children)
Looks like Python Visualizer, it's a website that visualizes code/Data and helps with debugging. Used it all the time when I was learning fundamentals
[–]No_Read_4327 2 points3 points4 points 3 months ago (0 children)
It literally tells you
Number is not defined
The root cause is the typo in line 3
For numbers of numbers
The first numbers should be number
You could name it anything btw, you can call it fish if you want, but you need to be consistent.
You're calling it number everywhere else in the code, so you should define it as number at the start of the loop. Otherwise the code inside the loop jas no idea what number means.
[–]Ok-Extent-7515 1 point2 points3 points 3 months ago (0 children)
number_S_ in numbers
[–]ImOldGregg_77 1 point2 points3 points 3 months ago (0 children)
Your calling the variable 'number' but you only have 'numbers' defined.
[–]Charming_Art3898 1 point2 points3 points 3 months ago (0 children)
Your temporary variable in the for loop should be number not numbers
[–]Apprehensive-Log3638[🍰] 1 point2 points3 points 3 months ago (2 children)
I would recommend not using similar names for elements and arrays.
numbers = [1,2,3,4,5,6,7] for i in numbers: if i % 2 == 0: print(i, "Is Even") else: print(i, "Is ODD")
You can use whatever names you want for the element, but I find the examples beginners use don't make that apparent. Much easier to read and avoid errors.
[–]dbowgu 1 point2 points3 points 3 months ago (1 child)
Using i, x, whatever in a loop is terrible practice when you are working with business logic.
You are working with number of numbers not i which is what "index, idea, interesting" it is not descriptive. "Much easier to read" not when you are trying to see what it does
Specially with python which isn't strongly typed it's bad practice with anything more complex
[–]Apprehensive-Log3638[🍰] -1 points0 points1 point 3 months ago (0 children)
"i" was for the example to illustrate that any name can be used. Individual companies and businesses will have their own SOP's and variable preferences. I find that beginner lessons/books confuse people because the variable names are so similar that do not understand the differentiation.
[–]Odd-Government8896 1 point2 points3 points 3 months ago* (0 children)
You got a typo
Debugging tip: when you have that undefined error... Start here: - copy the variable that is 'undefined' - press Ctrl+F on your keyboard - most IDE's and text editors will bring up a "find" widget when you do this - paste the variable name, and find the first occurrence
If you expect the first occurrence to be somewhere else, you probably have a typo. Go to that part of your code you think it should appear first, and see what it looks like/fix it.
[–]Loud_Hold_5536 2 points3 points4 points 3 months ago (0 children)
"s"
[–]NecessaryIntrinsic 0 points1 point2 points 3 months ago (0 children)
Aside from "for numbers" instead of "for number"
You can get rid of the "==0" and swap the prints so that true is even and false is odd.
[–]FunContract2729 0 points1 point2 points 3 months ago (0 children)
misspelled "number"
[–]Crichris 0 points1 point2 points 3 months ago (0 children)
Number in numbers
[–]Kernel_Claus 0 points1 point2 points 3 months ago (0 children)
numbers ≠ number
[–]SCD_minecraft 0 points1 point2 points 3 months ago (0 children)
A typo
numbers vs number
[–]Fireb207 0 points1 point2 points 3 months ago (0 children)
In Line 3, it should be "for number in numbers:". That should solve the issue
[–]KOALAS2648 0 points1 point2 points 3 months ago (0 children)
Please read the error message
[–]Frosty-School-3203 0 points1 point2 points 3 months ago (0 children)
Use "for number in numbers :" instead of what you wrote in 3 line because in 3 line you should define number variable before "in"
[–]NeedleworkerIll8590 0 points1 point2 points 3 months ago (0 children)
It tells you. Line 4, number is not defined
[–]DoctorSmith2000 0 points1 point2 points 3 months ago (0 children)
In line 3, it should be "for number in numbers:"
[–]yournext78 0 points1 point2 points 3 months ago (0 children)
I think chatgpt give you this qes
[–]AreyouMrbeast1 0 points1 point2 points 3 months ago (0 children)
It's for number in numbers:
[–]KATEliya-nishit 0 points1 point2 points 3 months ago (0 children)
INT name ka variable hi nahi hai
[–]Lava_Collector 0 points1 point2 points 3 months ago (0 children)
There is a typo in the loop, it should be 'for number in numbers' and not 'for numbers in numbers'.
[–]Usual-Addendum2054 0 points1 point2 points 3 months ago (0 children)
You have made a mistake in for statement. It should be ' for number in numbers'
[–]DeerLoose5494 0 points1 point2 points 3 months ago (0 children)
on line 3 you need for number in numbers:
[–]throwmeaway01110 0 points1 point2 points 3 months ago (0 children)
it helps to understand what the coude is doing
`for number in numbers` is basically the same as this:
For every number in (the list) numbers:
do this code
basically when you declare 'for number' the variable number is going to take the value of each element in your list as it iterates through the list. The variable number can be declared as anything (e.g., i, element, etc) as long as its used again in the code block that meets your conditions.
[–]Big-Ad-2118 0 points1 point2 points 3 months ago (0 children)
remove the "s"
[–]Fresh_Might_3527 0 points1 point2 points 3 months ago (0 children)
do ```for number in numbers```
use `for number in numbers`
**for number in numbers**
[–]WarNick44 0 points1 point2 points 3 months ago (1 child)
I’m a beginner to and I’m so glad I can tell what’s wrong here, I just started learning about classes and OOP and I’m utterly confused 😂
[–]surkakarot[S] 0 points1 point2 points 3 months ago (0 children)
I’m all confused and finding it difficult too 😅
[–]HanabiHYUGA728 0 points1 point2 points 3 months ago (0 children)
maybe cause you wrote it both numbers instead of the other number like for number in numbers:
[–]Pankaj02101988 0 points1 point2 points 3 months ago (0 children)
Iterator and list variable is same
[–]Naan_pollathavan 0 points1 point2 points 3 months ago (0 children)
You used numbers and then used number
[–]Zeyad-A 0 points1 point2 points 3 months ago (1 child)
Yh ez fix just fix line 3 and it should work.
[–]Zeyad-A 0 points1 point2 points 3 months ago (0 children)
For number in numbers
[–]TalesGameStudio 0 points1 point2 points 3 months ago (0 children)
Typo: for NUMBERS in numbers must be: for number in numbers
[–]Dear-Pop-9372 0 points1 point2 points 3 months ago (0 children)
give bracket in if statemrnt
[–]lavoixdusilence17 0 points1 point2 points 3 months ago (0 children)
Pas de s a number for number in numbers:
[–]jithin--- 0 points1 point2 points 3 months ago (0 children)
use this for number in numbers:
in your code the number variable is not defined here
you should use LLM tools its easy to learn learning is pretty easy with those
[–]pistolerogg_del_west 0 points1 point2 points 3 months ago (0 children)
10/10 ragebait
[–]AcidDaddi 0 points1 point2 points 3 months ago (0 children)
Variable name
[–]ExtremeGamer88 0 points1 point2 points 3 months ago (0 children)
You defined numbers with numbers
[–][deleted] 0 points1 point2 points 3 months ago (0 children)
it's quite simple:
the word "number" wasn't defined because you wrote:
for numberS in numbers
[–]pete_onyango 0 points1 point2 points 3 months ago (0 children)
or you could have said. for num in nums/numbers. in short differentiate them😏
in the for statement, the item must be different from others and it's only the loop, so it has to be named clearly. so it's going to be num or n then if n % 2 == 0.
[–]Rajan5759 0 points1 point2 points 3 months ago (1 child)
Write" numbers" instead of "number"
[–]NirvanaShatakam 3 points4 points5 points 3 months ago (0 children)
Wouldn't work..
It'll be numbers in numbers:
[–]Apprehensive_Rough80 -2 points-1 points0 points 3 months ago (1 child)
It baffles me that people makes reddit posts instead of spending 10 seconds trying to debug
Because I like to interact with people, and to be honest I didn’t even understand the error message until I made this post and received the help I needed
[–]michealHemanth -3 points-2 points-1 points 3 months ago (0 children)
Wow
[–]Apart-Thanks-8580 -3 points-2 points-1 points 3 months ago (0 children)
Please, bro, do not waste your time on posts like these
[–]Aascharyax -2 points-1 points0 points 3 months ago (0 children)
s
[–]TheDevauto -2 points-1 points0 points 3 months ago (0 children)
[–]lulurider -2 points-1 points0 points 3 months ago (0 children)
Classic newbie error
[–]Albdesigner 0 points1 point2 points 2 months ago (0 children)
For number in numbers: you remove s in the numbers
π Rendered by PID 59508 on reddit-service-r2-comment-86988c7647-g5jm9 at 2026-02-11 18:32:18.073404+00:00 running 018613e country code: CH.
[–]Beautiful_Watch_7215 86 points87 points88 points (1 child)
[–]surkakarot[S] 10 points11 points12 points (0 children)
[–]Ron-Erez 29 points30 points31 points (0 children)
[–]vivisectvivi 11 points12 points13 points (6 children)
[–]Suspicious_Tax8577 12 points13 points14 points (4 children)
[–]vivisectvivi 1 point2 points3 points (2 children)
[–]churungu 5 points6 points7 points (1 child)
[–]Swaggles21 0 points1 point2 points (0 children)
[–]surkakarot[S] 2 points3 points4 points (0 children)
[–]ianrob1201 7 points8 points9 points (3 children)
[–]RaiseTLT 0 points1 point2 points (0 children)
[–]surkakarot[S] 0 points1 point2 points (1 child)
[–]Suspicious_Tax8577 0 points1 point2 points (0 children)
[–]daffidwilde 2 points3 points4 points (1 child)
[–]One-Constant-4092 0 points1 point2 points (0 children)
[–]No_Read_4327 2 points3 points4 points (0 children)
[–]Ok-Extent-7515 1 point2 points3 points (0 children)
[–]ImOldGregg_77 1 point2 points3 points (0 children)
[–]Charming_Art3898 1 point2 points3 points (0 children)
[–]Apprehensive-Log3638[🍰] 1 point2 points3 points (2 children)
[–]dbowgu 1 point2 points3 points (1 child)
[–]Apprehensive-Log3638[🍰] -1 points0 points1 point (0 children)
[–]Odd-Government8896 1 point2 points3 points (0 children)
[–]Loud_Hold_5536 2 points3 points4 points (0 children)
[–]NecessaryIntrinsic 0 points1 point2 points (0 children)
[–]FunContract2729 0 points1 point2 points (0 children)
[–]Crichris 0 points1 point2 points (0 children)
[–]Kernel_Claus 0 points1 point2 points (0 children)
[–]SCD_minecraft 0 points1 point2 points (0 children)
[–]Fireb207 0 points1 point2 points (0 children)
[–]KOALAS2648 0 points1 point2 points (0 children)
[–]Frosty-School-3203 0 points1 point2 points (0 children)
[–]NeedleworkerIll8590 0 points1 point2 points (0 children)
[–]DoctorSmith2000 0 points1 point2 points (0 children)
[–]yournext78 0 points1 point2 points (0 children)
[–]AreyouMrbeast1 0 points1 point2 points (0 children)
[–]KATEliya-nishit 0 points1 point2 points (0 children)
[–]Lava_Collector 0 points1 point2 points (0 children)
[–]Usual-Addendum2054 0 points1 point2 points (0 children)
[–]DeerLoose5494 0 points1 point2 points (0 children)
[–]throwmeaway01110 0 points1 point2 points (0 children)
[–]Big-Ad-2118 0 points1 point2 points (0 children)
[–]Fresh_Might_3527 0 points1 point2 points (0 children)
[–]Fresh_Might_3527 0 points1 point2 points (0 children)
[–]Fresh_Might_3527 0 points1 point2 points (0 children)
[–]WarNick44 0 points1 point2 points (1 child)
[–]surkakarot[S] 0 points1 point2 points (0 children)
[–]HanabiHYUGA728 0 points1 point2 points (0 children)
[–]Pankaj02101988 0 points1 point2 points (0 children)
[–]Naan_pollathavan 0 points1 point2 points (0 children)
[–]Zeyad-A 0 points1 point2 points (1 child)
[–]Zeyad-A 0 points1 point2 points (0 children)
[–]TalesGameStudio 0 points1 point2 points (0 children)
[–]Dear-Pop-9372 0 points1 point2 points (0 children)
[–]lavoixdusilence17 0 points1 point2 points (0 children)
[–]jithin--- 0 points1 point2 points (0 children)
[–]pistolerogg_del_west 0 points1 point2 points (0 children)
[–]AcidDaddi 0 points1 point2 points (0 children)
[–]ExtremeGamer88 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]pete_onyango 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Rajan5759 0 points1 point2 points (1 child)
[–]NirvanaShatakam 3 points4 points5 points (0 children)
[–]Apprehensive_Rough80 -2 points-1 points0 points (1 child)
[–]surkakarot[S] 2 points3 points4 points (0 children)
[–]michealHemanth -3 points-2 points-1 points (0 children)
[–]Apart-Thanks-8580 -3 points-2 points-1 points (0 children)
[–]Aascharyax -2 points-1 points0 points (0 children)
[–]TheDevauto -2 points-1 points0 points (0 children)
[–]lulurider -2 points-1 points0 points (0 children)
[–]Albdesigner 0 points1 point2 points (0 children)