Skip to content

Instantly share code, notes, and snippets.

@athursto
Last active August 21, 2023 16:25
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 athursto/2dee2d813b818ba4429295cf1cb0d3bb to your computer and use it in GitHub Desktop.
Save athursto/2dee2d813b818ba4429295cf1cb0d3bb to your computer and use it in GitHub Desktop.
"""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