Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Number Guessing Game - Mike Kerry
- import random
- while True:
- target = random.randint(1, 100)
- for tries in range(6):
- while True:
- user = input("\nMake a guess 1 through 99: ")
- if user.isnumeric():
- break
- print("integers only!! Try again")
- n = int(user)
- if n == target:
- print("You guessed correctly in", tries, "tries")
- break
- text = "higher" if n < target else "lower"
- print("\nYou need to guess", text)
- print("You have", 5-tries, "tries remaining")
- else:
- print("Sorry, you lost. The correct number was", target)
- yn = input("\nPlay again? (y/n): ")
- if yn not in ["Y", "y"]:
- break
Add Comment
Please, Sign In to add comment