Jun-18-2020, 04:21 PM
Hey guys,
I'm a beginner at coding and I'm trying to create this game where a person has to guess the word and only has 3 guesses. Now my simple problem is that, I want to interrupt the while loop so that after 2 guesses, it prints out "You only have 1 guess remaining"
I've tried a few ways but I still can't figure out how to do it. Any tips would be great :)
I'm a beginner at coding and I'm trying to create this game where a person has to guess the word and only has 3 guesses. Now my simple problem is that, I want to interrupt the while loop so that after 2 guesses, it prints out "You only have 1 guess remaining"
I've tried a few ways but I still can't figure out how to do it. Any tips would be great :)
secret_word = "giraffe" # this is the secret word
guess = "" # variable to store the words
guess_count = 0
guess_limit = 3
out_of_guesses = False
two = 3
ifTwo = False
while guess != secret_word and not(out_of_guesses): #if they havent guessed the word yet and have not ran out of guesses, then keep looping.
if guess_count < guess_limit:
guess = input("Enter Guess:")
guess_count += 1
#elif guess_count == 2:
# print("Last quess")
else:
out_of_guesses = True
if out_of_guesses:
print("Unlucky mate, out of guesses.")
else:
print("You've guessed correctly!")
