Skip to content

Instantly share code, notes, and snippets.

@joetechem
Created April 10, 2017 17:38
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 joetechem/775e0acaaabc2a3aaddb2b0eb64d2685 to your computer and use it in GitHub Desktop.
Save joetechem/775e0acaaabc2a3aaddb2b0eb64d2685 to your computer and use it in GitHub Desktop.
program chooses from a range of random numbers for the user to guess
# Python 2.7
# Code Em Level 2 - Icebreaker
# a program to generate random numbers by using the random module
# a random number is picked, and the user must guess the number between 1 and 100.
import random
number = random.randint(1, 100)
print("I'm thinking of number between 1 and 100")
print("Try to guess the number with as few attempts as possible")
print("Here's my hint, try to use a binary search method!")
GameRunning = True
while True:
guess = int(input("Guess a number between 1-100: "))
if guess == number:
GameRunning = True
print("You guessed correctly!")
elif guess > number:
print("Your guess was too high")
elif guess < number:
print("Your guess was too low")
else:
print("Your did not enter a number")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment