import random
a=random.randint(1,100)
global c
c=20
def guess(b):
if c != 0:
if a>b:
print('greater')
elif a==b:
print('you win')
c=20
a=random.randint(1,100)
else:
print('lower')
c -= 1
else:
print('you lose')
c=20
says c is not a global variable
UnboundLocalError: cannot access local variable 'c' where it is not associated with a value
You should declare that c
is global
inside the function.
how?
,.,..,
Put the global c
in inside the function.
1 Like