Last active
August 21, 2023 16:25
-
-
Save athursto/2dee2d813b818ba4429295cf1cb0d3bb 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
"""8.21.2023""" | |
"""Make a "guessing game" where there is a target number, and as the user makes guesses, the output returns | |
higher or lower until the user is correct.""" | |
def guessing_game(target_number): | |
guess_count = 0 | |
s = -10000 | |
if type(target_number) != int: | |
print("Please enter an integer and try again.") | |
while s!= target_number: | |
s = int((input("Guess the number!"))) | |
if target_number > s: | |
print("higher") | |
elif target_number < s: | |
print("lower") | |
guess_count += 1 | |
if s == target_number: | |
print(f"Correct! You won in {guess_count} guesses!") | |
guessing_game(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment