Skip to content

Instantly share code, notes, and snippets.

@ehedaoo
Created May 16, 2017 07:39
Show Gist options
  • Save ehedaoo/1ae97b9c81d78ccbff57326fd313d76b to your computer and use it in GitHub Desktop.
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.
# 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