name 'x' is not defined, Why?
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?
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
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.