jeudi 28 mai 2015

python guess the number - try again after overguessing

I have made a simple Guess the number program, but i don't know how to make the try again after guessing wrong 3 times. Any tips and tricks?

from random import randint
for i in range(1): 
random_value = randint (1,10)

print "Guess the number"
tryes = 1
while tryes <= 3:
guess_1 = input('>')

    if guess_1 > random_value:
        print "The number is lower"
        tryes = tryes + 1
    elif guess_1 < random_value:
        print "The number is higher"
        tryes = tryes + 1
    elif guess_1 == random_value:
        print "You guessed right"
        tryes = tryes + 3
    else:
        print "Invalid answer"

print "You won! Lets try that again shall we?"




Aucun commentaire:

Enregistrer un commentaire