Skip to content

Instantly share code, notes, and snippets.

@kybr
Created January 24, 2017 14:50
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 kybr/3b52d389ab22327fa21785f7218776bd to your computer and use it in GitHub Desktop.
Save kybr/3b52d389ab22327fa21785f7218776bd to your computer and use it in GitHub Desktop.
# Karl's solution from "translation"
#
# Write a Python program
import random
# to guess a (random) number between 1 and 100.
secret = random.randint(1,100)
howmany = 0
# You will need to use a while loop to keep *the program* running
while True:
# that asks the user === input
guess = input("Give me a number: ")
howmany = howmany + 1
# *If* the *guess* is right, === until the number is correct.
if guess == secret:
# telling the user *how many* tries it took.
print("Right!")
print("You got it in " + str(howmany) + " tries")
# the program [exits]
exit()
# If *it* is wrong,
if guess != secret:
# the program will tell the user whether the number is higher or lower.
if guess < secret:
print("Sorry, too low.")
else:
print("Sorry, too high.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment