jeudi 7 juillet 2016

Python if loop doesn't function/repeats ineffectively

print("Guess a number between 1 and 100")  
userGuess = int(input("Your guess: "))   
import random      
randomNumber = (random.randint(1,100))

found = False

while userGuess in range(1,100):  
if userGuess > randomNumber:  
   int(input("Guess lower: "))  
   found = False  
elif userGuess < randomNumber:   
    int(input("Guess higher: "))  
    found = False  
else:  
    print("You got it!")      
    found = True  

When guessing the number, after your first guess it will use the right higher/lower if/elif statement, but every guess thereafter will be looped back into whichever statement was used the first time. Ends up repeating the same thing even if i go out of range. I know theres a lot of these threads for this program but i couldn't figure out what my issue was, any help is much appreciated!

Aucun commentaire:

Enregistrer un commentaire