cis_projects/ps1_4_joseph_green.py

39 lines
904 B
Python
Raw Normal View History

2017-02-11 16:21:29 -07:00
#Random number 1:9 (including 1/9)
#have user guess, respond with high or low
#Keep going untill "exit" is typed
#keep track of number of guesses
import random
guesses = 0
playerGuess = None
answer = random.randint(1,9)
print("Welcome to the classic high/low game!!!")
while True:
playerGuess = input("Please enter an integer 1-9 or type 'exit' to quit: ")
if playerGuess != "exit":
try:
playerGuess = int(playerGuess)
except:
print ("Please only enter integers between 0 and 10, or type 'exit' to quit.")
continue
elif playerGuess == "exit":
break
if playerGuess == answer:
print("Congrats! You guessed right! ")
elif playerGuess > answer:
print("You guessed too high!")
elif playerGuess < answer:
print("You guessed too low!")
guesses += 1
print("You made", guesses, "guesses.")