Last active
April 8, 2021 22:41
-
-
Save ryanorsinger/17f573658706e294a798d01bd4a8b4de to your computer and use it in GitHub Desktop.
Prompting a user for a number
This file contains hidden or 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
# 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