Skip to content

Instantly share code, notes, and snippets.

@nicolasfig
Created October 16, 2012 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolasfig/3902642 to your computer and use it in GitHub Desktop.
Save nicolasfig/3902642 to your computer and use it in GitHub Desktop.
Guess my number simple text game
import random
guessesTaken = 0
print("Hello what is your name?")
name = input()
number = random.randint(1,20)
print("Well",name,",I am thinking of a number between 1 and 20.")
while guessesTaken < 6:
print("Take a guess")
guess = input()
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number:
print("your guess is to low")
if guess > number:
print("Your guess is to high")
if guess == number:
break
if guess == number:
guessesTaken = str(guessesTaken)
print("Good job",name,"You guessed my number in",guessesTaken,"guesses!")
if guess != number:
number = str(number)
print("Nope, the number I was thinking of was",number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment