Hello guys and thank you in advance for reading my post.
I am writing the following module which will ask the end-user to guess a number and after x amount of guesses a message should appear to says "Sorry, you have tried x times already"
This is what I have so far.
I don't know how to limit the amount of guesses. can anyone explain how that can be accomplished?
I am starting to learn the while loop.
Thank you again.
I am writing the following module which will ask the end-user to guess a number and after x amount of guesses a message should appear to says "Sorry, you have tried x times already"
This is what I have so far.
Code:
n = 56
while True:
guess = int(input("Guess a number: "))
if guess > n:
print("Guess lower")
elif guess < n:
print("Guess higher")
elif guess == n:
print("Congrats!, you have guessed the right number")
break
I am starting to learn the while loop.
Thank you again.
Comment