Created
May 16, 2017 07:39
-
-
Save ehedaoo/1ae97b9c81d78ccbff57326fd313d76b to your computer and use it in GitHub Desktop.
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.
This file contains 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
# 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. | |
import random | |
num = random.randint(1, 10) | |
flag = 0 | |
def guessnum(num, player, flag): | |
if player == num: | |
print("Same") | |
flag += 1 | |
print("You took " + str(flag) + " chances.") | |
elif player < num: | |
print("You have entered a low value.. Try again!") | |
bleh = int(input("Enter a new Number: ")) | |
flag += 1 | |
guessnum(num, bleh, flag) | |
elif player > num: | |
print("You have entered a higher value.. Try again!") | |
bleh = int(input("Enter a new Number: ")) | |
flag += 1 | |
guessnum(num, bleh, flag) | |
test = int(input("Do you want to play a game? 1 to enter, 2 to exit: ")) | |
if test == 1: | |
player = int(input("Guess the number: ")) | |
guessnum(num, player, flag) | |
elif test == 2: | |
print("Okay Bye") | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment