+ 3
Beginner code issues
Having trouble with my game 1 code it’s a guessing game an I can’t seem to figure out what’s wrong with elif
3 Antworten
+ 2
Try this instead
import random
n = random.randint(1,99)
guess = input("enter an interger from 1 to 99:"))
while n != "guess":
print
if guess <n:
print ("guess is low,try again")
guess = input("enter integer from 1 to 99:"))
elif guess >n:
print ("guess is high, try again")
guess = input("enter integer from 1 to 99:"))
else:
print ("you guessed it")
break
+ 1
Your problem was with the spacing of the code, some missing parenthesis, and some missing quotation marks
0
your problem is a missing space: elif only works if your still in an if statement: (# for spaces to make it better visible)
#if :
##methods()
#elif :
but you made:
#if :
#methods()
#elif :
so it thinks the if part is completed with the methods() statement