Advertisement
jinglis

Guess My Number Game

Sep 22nd, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. # Name: James Inglis
  2. # Course: Robotics Programming
  3. # Professor: Ms.Stockbridge
  4. # Date: 9/22/14
  5. # Description: This program is the, "Guessing My Number" game
  6. #              on pg 82 in Python Programming Third Edition.
  7. #
  8.  
  9. import random
  10.  
  11. # Displaying the directions.
  12. print("\tWelcome to \'Guess My Number\'!")
  13. print("\nI'm thinking of a number between 1 and 100.")
  14. print("Try to guess it in as few attempts as possible.\n")
  15.  
  16. # Storing and asking for a number.
  17. the_number = random.randint(1, 100)
  18. guess = int(input("Take a guess: "))
  19. tries = 1
  20.  
  21.  
  22. # If the guess is over the number, display lower.
  23. # Otherwise, display higher.
  24. while guess != the_number:
  25.     if guess > the_number:
  26.         print("Lower....")
  27.     else:
  28.         print("Higher...")
  29.  
  30.     guess = int(input("Take a guess: "))
  31.     tries += 1
  32.  
  33. print("You guessed it!! The number was", the_number)
  34. print("And it only took you", tries, "tries!\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement