Created
September 20, 2015 17:43
-
-
Save ludwa6/bbad2fcfd4ee5bc48595 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 a number between 1 and 100 in seven tries | |
import random | |
answer = 'yes' | |
while answer == "yes": | |
NumToGuess = random.randint(1, 100) | |
NumOfTry = 7 | |
print '' | |
print "I am thinking of a number between 1 and 100" | |
print "Try to guess the number in 7 tries" | |
print '' | |
while NumOfTry != 0: | |
try: | |
x = int (input ("Please enter a number: ")) | |
if x > NumToGuess: | |
NumOfTry = NumOfTry - 1 | |
print "You guessed ",x,"... That's too high!" | |
print "You have",NumOfTry, "attempt(s) left" | |
print ("") | |
elif x < NumToGuess: | |
print "You guessed ",x,"... That's too low!" | |
NumOfTry = NumOfTry - 1 | |
print "You have ",NumOfTry, "attempt(s) left" | |
print ("") | |
elif x == NumToGuess: | |
print ("You Win, Congratulations!!!") | |
NumOfTry = 0 | |
except: | |
print ("Please enter a valid number. For example 1, 5 an 44 are valid numbers to input.") | |
else: | |
print "The number to guess was: " + str(NumToGuess) | |
answer = raw_input ('Do you want to play again? (yes/no)') | |
else: | |
print ("Thank you for playing. Goodbye") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment