Last answered:

03 Jan 2022

Posted on:

01 Jan 2022


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?


1 answers ( 0 marked as helpful)
Posted on:

03 Jan 2022


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.

Submit an answer