Skip to content

Instantly share code, notes, and snippets.

@odanga94
Created May 12, 2017 15:24
Show Gist options
  • Save odanga94/a103f1ebcba4b53245472e5e900a0bca to your computer and use it in GitHub Desktop.
Save odanga94/a103f1ebcba4b53245472e5e900a0bca to your computer and use it in GitHub Desktop.
PracticePython/Exercise9
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