Created
February 15, 2011 00:44
-
-
Save anonymous/826892 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Guess My Number | |
# | |
# The computer picks a random number between 1 and 100 | |
# The player tries to guess it and the computer lets | |
# the player know if the guess is too high, too low | |
# or right on the money | |
import random | |
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") | |
# set the initial values | |
the_number = random.randint(1, 100) | |
guess = int(input("Take a guess: ")) | |
tries = 5 | |
# guessing loop | |
while guess != the_number: | |
if guess > the_number: | |
print("Lower...") | |
else: | |
print("Higher...") | |
guess = int(input("Take a guess: ")) | |
tries = int(input("How many tries do you want: ")) | |
if tries == 5 | |
print("You have 5 tries left!") | |
print("You guessed it! The number was", the_number) | |
print("And it only took you", tries, "tries!\n") | |
input("\n\nPress the enter key to exit.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment