Skip to content

Instantly share code, notes, and snippets.

@lucasmelin
Created May 9, 2016 14:06
Show Gist options
  • Save lucasmelin/ba8b0606aa6d195ee4d21f5db5baf3ff to your computer and use it in GitHub Desktop.
Save lucasmelin/ba8b0606aa6d195ee4d21f5db5baf3ff to your computer and use it in GitHub Desktop.
Simple number guessing game
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