From cfd4315ce0528325cab272e073c267d4a5a6a5c8 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Sat, 11 Feb 2017 16:21:29 -0700 Subject: [PATCH] 2 and 4 added --- ps1_2_joseph_green.py | 1 - ps1_4_joseph_green.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ps1_2_joseph_green.py b/ps1_2_joseph_green.py index 30f9e10..8bae09e 100644 --- a/ps1_2_joseph_green.py +++ b/ps1_2_joseph_green.py @@ -16,4 +16,3 @@ try: print(str(number) + ",is an " + evenOdd + " number") except: print("Only enter an integers!") - diff --git a/ps1_4_joseph_green.py b/ps1_4_joseph_green.py index e69de29..d3f0158 100644 --- a/ps1_4_joseph_green.py +++ b/ps1_4_joseph_green.py @@ -0,0 +1,38 @@ +#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.")