Created
February 18, 2021 01:19
-
-
Save gsinclair/67053c5d60a3857ddf9e8504963f3962 to your computer and use it in GitHub Desktop.
Computer guessing game
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
import random | |
UPPER_LIMIT = 1000000 | |
target = random.randint(1, UPPER_LIMIT) | |
print("I've chosen a number between 1 and", UPPER_LIMIT) | |
num_guesses = 0 | |
while True: | |
print() | |
try: | |
guess = int(input("Input your guess: ")) | |
num_guesses += 1 | |
except ValueError: | |
print("Can't interpret your input; try again") | |
continue | |
if guess > target: | |
print("Lower") | |
elif guess < target: | |
print("Higher") | |
else: | |
print("CORRECT!!!") | |
print() | |
print("It took you", num_guesses, "guesses to get the correct number") | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment