name 'x' is not defined, Why?
Hello~
Happy new year!
Counld anyone explain to me why my answer (in the following picture) dosen't work?
The only difference here is "numbers[x]" rather the correct answer "numbers[tot]"
And Why the "tot" can be defined as a variable in "numbers" but also function like a a counter simultaneously?
Hi JaLego!
Thanks for reaching out.
In your code, you are defining a function containing a while loop, and within that function, you have not defined a variable called x
. In the meantime, you do define tot
(standing for "total"). That's the reason why Python is unable to create the count()
function.
In other words, please pay attention to the flow of variable declarations and statements while creating Python functions and iterations (and, actually, any other Python tool!).
Hope this helps.
Best,
Martin