Prevent the user from breaking the program

Asked

Viewed 32 times

1

I would like the code not to break if the user puts a letter in place of a number in the variable: kick. This piece of code works very well if the user adds number, but if you add a letter, it’s gone! The code breaks.

Thank you very much from now on

chute = input("Escolha quantos chutes você pode dar! Escolha um numero entre 1 e 7")

if (int(chute) < 1 ):
    print("XXX")
    jogar()
elif (int(chute) > 7):
    print("YYY")
    jogar()
else:
    print("Ok, você tem {} chutes" .format(chute))
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.