Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Name: James Inglis
- # Course: Robotics Programming
- # Professor: Ms.Stockbridge
- # Date: 9/22/14
- # Description: This program is the, "Guessing My Number" game
- # on pg 82 in Python Programming Third Edition.
- #
- import random
- # Displaying the directions.
- print("\tWelcome to \'Guess My Number\'!")
- print("\nI'm thinking of a number between 1 and 100.")
- print("Try to guess it in as few attempts as possible.\n")
- # Storing and asking for a number.
- the_number = random.randint(1, 100)
- guess = int(input("Take a guess: "))
- tries = 1
- # If the guess is over the number, display lower.
- # Otherwise, display higher.
- while guess != the_number:
- if guess > the_number:
- print("Lower....")
- else:
- print("Higher...")
- guess = int(input("Take a guess: "))
- tries += 1
- print("You guessed it!! The number was", the_number)
- print("And it only took you", tries, "tries!\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement