Created
April 20, 2016 20:12
-
-
Save Lvl4Sword/8753f0f4be5fd960df1544d0b24edff6 to your computer and use it in GitHub Desktop.
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
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