diff --git a/randomNumbers.py b/randomNumbers.py index 2f37300..d20aab6 100644 --- a/randomNumbers.py +++ b/randomNumbers.py @@ -1,9 +1,25 @@ -import random - -bottom = int(raw_input('\nWhat is the bottom number in your range?\n> ')) -top = int(raw_input('\nWhat is the top number in your range?\n> ')) - -while __name__ == '__main__': - print '\n' * 25 - print random.randint(bottom, top) - raw_input('\nPress Enter for another.') +from random import randint +print("Hello the game begins") +number = randint(0,20) +attempt = 3 +def trying(): + try: + global attempt + userNumber = input("Nubmer: ") + if int(userNumber) > number and attempt > 1: + attempt = attempt - 1 + print("You have a " + str(attempt) + " attempts") + print("Try a smaller number") + trying() + elif int(userNumber) < number and attempt > 1: + attempt = attempt - 1 + print("You have a " + str(attempt) + " attempts") + print("Try a bigger number") + trying() + elif int(userNumber) == number and attempt > 1: + input("You win!") + else: + print("Game over\nThe number is ",number) + except ValueError: + print("ERROR. Try again please") +trying()