Created
May 12, 2017 15:24
-
-
Save odanga94/a103f1ebcba4b53245472e5e900a0bca to your computer and use it in GitHub Desktop.
PracticePython/Exercise9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
true_value = randint(1, 9) | |
print(true_value) | |
count = 0 | |
while True: | |
user_guess = int(input("Guess a number between 1 and 9: ")) | |
count += 1 | |
if user_guess == true_value: | |
print("You guess was correct. Congratulations!!") | |
break | |
else: | |
continue_msg = raw_input("Your guess was incorrect. Type 'exit' to quit game or 'play' to keep trying: ") | |
if continue_msg == "play": | |
if user_guess > true_value: | |
print("You guessed too high, guess lower") | |
else: | |
print("You guessed too low, guess higher") | |
elif continue_msg == "exit": | |
break | |
else: | |
print("You entered an invalid response. Try again") | |
print("You made %d guess(es)") %(count) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment