SHARE
TWEET

Untitled

a guest Nov 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This is a guess the number game
  2. import random
  3.  
  4. print 'Hello. What is your name?'
  5. name = raw_input()
  6.  
  7. print 'Well ' + name + ', I am thinking of a number between 1 and 20.'
  8. secret_number = random.randint(1,20)
  9.  
  10. for guesses_taken in range(7):
  11.     print 'Take a guess.'
  12.     try:
  13.         guess = int(raw_input())
  14.     except ValueError:
  15.         print 'Please type a number for this game to work'
  16.         continue
  17.  
  18.     if guess < secret_number:
  19.         print 'Your guess is too low.'
  20.     elif guess > secret_number:
  21.         print 'Your guess is too high.'
  22.     else:
  23.         break # This condition is for the correct guess only
  24.  
  25. if guess == secret_number:
  26.     print 'Good job, ' + name + ' ! You guessed my number in ' + str(guesses_taken) + ' guesses'
  27. else:
  28.     print 'Nope. The number I was thinking of was ' + str(secret_number)
  29.  
  30.  
  31. print 'You took ' + str(guesses_taken) + ' guesses.'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top