Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Computer Guesses Number
- import random
- # first whiletrue for the "replay" mechanic
- while True:
- low = 1
- high = 100
- print("I will guess your number from 1 to 100 because I am SMART computer!")
- input("Press Enter when ready.")
- # second whiletrue for the reguessing mechanic
- while True:
- guess = random.randint(low, high)
- print("\nI guess the number", guess, ".")
- while True:
- # third whiletrue to reask the question when user types something other than
- # 'higher', 'lower', and 'correct'
- result = input("Is your number 'higher', 'lower', or is this 'correct'? ")
- if result == "higher":
- low = guess + 1
- break
- elif result == "lower":
- high = guess - 1
- break
- elif result == "correct":
- print("I am smrt. :3 \n")
- break
- else:
- continue
- if result != "correct":
- continue
- else:
- break
- retry = input("Press 'r' to play again, or press any other key to exit.")
- if retry == "r" or retry == "R":
- continue
- else:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement