Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialYoussef Moustahib
7,779 PointsWhy do I keep getting this error message?
I keep getting the error message:
Traceback (most recent call last):
File "numbertest.py", line 25, in <module>
main()
File "numbertest.py", line 7, in main
while guesses > 0:
UnboundLocalError: local variable 'guesses' referenced before assignment
I thought "guesses" is a global variable as it is not inside the function? What is going on? Please see my code below
1 Answer
Oszkár Fehér
Treehouse Project ReviewerHi Youssef I guess the numbertest.py file is the problem, honestly i do'nt understand why it's not working but if you put before the while loop
global guesses
it works. I searched to see why, If youuse a global variable in a while or for loop you have to define first
var = 5
def something()
global var
while var:
the rest of the code...
like this is working For better understanding of this you can search StackOverflow. I hope it helped you. Happy coding