Created
May 9, 2016 14:06
-
-
Save lucasmelin/ba8b0606aa6d195ee4d21f5db5baf3ff to your computer and use it in GitHub Desktop.
Simple number guessing game
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
import random | |
secret = random.randint(0, 100) | |
guess = 0 | |
tries = 0 | |
print ("Try to guess the number between 1 and 100!") | |
print ("You have 7 tries.") | |
while guess != secret and tries < 7: | |
guess = int(input("What is your guess? ")) | |
if guess < secret: | |
print ("Too low, try again") | |
elif guess > secret: | |
print ("Too high, guess again") | |
tries = tries + 1 | |
if guess == secret: | |
print ("You got it!") | |
else: | |
print ("Looks like you ran out of guesses.") | |
print ("The answer was", secret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment