mercredi 8 juillet 2020

while and if statements problem with my script?

So I want to print "Wrong!" every time I get the wrong input. It works but when I type the right input it still executes the "if" statement despite "guess.capitalize() != secret_word" being false. Can you tell me what I'm doing wrong? multiple methods is appreciated !

secret_word = "Dog"
guess = ""
guess_count = 0
guess_limit = 3
out_of_guesses = False

while guess.capitalize() != secret_word and not out_of_guesses:
    if guess_count < guess_limit:
        guess = input("Enter your guess: ")
        guess_count += 1
        print("Wrong!")
    else:
        out_of_guesses = True

if out_of_guesses:
    print("You ran out of guesses")
else:
    print("You won!")

Aucun commentaire:

Enregistrer un commentaire