Now, what if user type wrong guess for the first guess and I want the terminal to print message like this “Sorry, you failed but you still have two chances”
And the user failed second chance again and I want the terminal to print message to user like this “Sorry, you failed your second chance but you still have your last chance”
Hi! There is more than one way, but here is how the code should look like to do what you want:
secret_number = 9
guess_count = 0
guess_limit = 3
while guess_count < guess_limit:
guess = input("Guess: ")
guess_count += 1
if guess == secret_number:
print("You won")
break
elif guess != secret_number and guess_count == 1:
print("Sorry, you failed but you still have two chances")
elif guess != secret_number and guess_count == 2:
print("Sorry, you failed your second chance but you still have your last chance")
else:
print ("You failed")