Skip to content

Instantly share code, notes, and snippets.

@Lvl4Sword
Created April 20, 2016 20:12
Show Gist options
  • Save Lvl4Sword/8753f0f4be5fd960df1544d0b24edff6 to your computer and use it in GitHub Desktop.
Save Lvl4Sword/8753f0f4be5fd960df1544d0b24edff6 to your computer and use it in GitHub Desktop.
import random
import sys
picked_num = random.randint(1, 10)
counter = 5
def guess_game(counter, picked_num):
while counter:
try:
number = int(input("Please choose a number between 1 and 10: "))
if 1 <= number <= 10:
if number == picked_num:
print("You guessed correctly! Woo!")
sys.exit()
else:
if 2 <= counter <= 5:
counter -= 1
if number > picked_num:
print("Your number was too high. {0} attempts left.".format(counter))
else:
print("Your number was too low. {0} attempts left.".format(counter))
elif counter == 1:
print('GAME OVER.')
sys.exit()
elif number <= 0:
print("BETWEEN 1 AND 10. NOT BELOW 1!")
elif number >= 11:
print("BETWEEN 1 AND 10. NOT ABOVE 10!")
except ValueError:
print("That is not a whole number")
guess_game(counter, picked_num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment