Created
January 24, 2017 14:50
-
-
Save kybr/3b52d389ab22327fa21785f7218776bd to your computer and use it in GitHub Desktop.
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
# 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