Created
November 30, 2017 04:58
-
-
Save azdafirmansyah/9e9721fc0fcb30ee95f3ce6be6a3398b to your computer and use it in GitHub Desktop.
Guessing Game One
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
''' | |
Exercie URL http://www.practicepython.org/exercise/2014/04/02/09-guessing-game-one.html | |
Generate a random number between 1 and 9 (including 1 and 9). Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly right. | |
Extras: | |
Keep the game going until the user types “exit” | |
Keep track of how many guesses the user has taken, and when the game ends, print this out. | |
''' | |
import random | |
num = random.randint(1,9) | |
while True: | |
try: | |
user_input = int(input("Input Guess Number ? \n > ")) | |
print(num, user_input) | |
if user_input == num: | |
print("Great, same number") | |
else: | |
if user_input > num: | |
print("Too High") | |
else: | |
print("Too Low") | |
except Exception as error: | |
print("Please input valid number\nLet's try again\n--------------------") | |
finally: | |
confirmation = input("press any key to continue or type 'exit' to stop \n > ") | |
if confirmation.lower() == 'exit': | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment