Advertisement
Chrispm84

Guess the number

Oct 12th, 2020
2,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. import random
  2.  
  3. randomNumber = random.randint(1, 20)
  4. print('I am thinking of a number between 1 and 20. Try to guess the number!')
  5.  
  6. guess = 0
  7. tries = 0
  8.  
  9. while int(guess) != randomNumber:
  10.     guess = input()
  11.     if int(guess) < randomNumber:
  12.         tries = tries + 1
  13.         print('Your guess is too low. Try again!')
  14.     elif int(guess) > randomNumber:
  15.         tries = tries + 1
  16.         print('Your guess is too high. Try again!')
  17. if int(guess) == randomNumber:
  18.     tries = tries + 1
  19.     print('Congratulations! You guessed the number in ' + str(tries) + ' tries!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement