Skip to content

Instantly share code, notes, and snippets.

@ryanorsinger
Last active April 8, 2021 22:41
Show Gist options
  • Save ryanorsinger/17f573658706e294a798d01bd4a8b4de to your computer and use it in GitHub Desktop.
Save ryanorsinger/17f573658706e294a798d01bd4a8b4de to your computer and use it in GitHub Desktop.
Prompting a user for a number
# Prompt the user to enter a number until they enter 5
while True:
# Obtain user input
number = input("Please input the number 5: ")
# Check if the input string is a digit
if number.isdigit():
# Now that we know the input is a digit, we can make sure to turn that string containing the number into an integer.
number = int(number)
# check if the digit is 5. If so, we get to exit the loop.
if number == 5:
break
else:
print("You entered some digit, but not the number 5")
else:
print("You did not enter a digit")
print("-----------")
print("Congratulations! You entered the number 5!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment