Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- name = input("Hello what is your name? ")
- # set the initial values
- start = input('Enter starting number : ')
- end = input('Enter ending number : ')
- the_number = random.randint(int(start), int(end))
- print("Hey " + name + ", I'm thinking of a number between", start, 'and', end)
- print("Try to guess it in less then 5 attempts.\n")
- # print(the_number) # I used this line to check if it worked
- guess = int(input("Take a guess: "))
- tries = 1
- # guessing loop
- while guess != the_number:
- tries+=1
- if tries > 5:
- print("Game Over! It took you more then 5 attempts. \n")
- print("The correct number was", the_number)
- break
- elif guess > the_number:
- print("Lower...")
- else:
- print("Higher...")
- guess = int(input("Take a guess: "))
- if guess == the_number:
- print("You guessed it " + name + "!" + " " + "The number was", the_number)
- print("And it only took you", tries, "tries!\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement