Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- randomNumber = random.randint(1, 20)
- print('I am thinking of a number between 1 and 20. Try to guess the number!')
- guess = 0
- tries = 0
- while int(guess) != randomNumber:
- guess = input()
- if int(guess) < randomNumber:
- tries = tries + 1
- print('Your guess is too low. Try again!')
- elif int(guess) > randomNumber:
- tries = tries + 1
- print('Your guess is too high. Try again!')
- if int(guess) == randomNumber:
- tries = tries + 1
- print('Congratulations! You guessed the number in ' + str(tries) + ' tries!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement