Skip to content

Instantly share code, notes, and snippets.

@mike-at-redspace
Last active February 2, 2023 23:20
Show Gist options
  • Save mike-at-redspace/c3c739b9a90f2db814c1fba0cc6d7f39 to your computer and use it in GitHub Desktop.
Save mike-at-redspace/c3c739b9a90f2db814c1fba0cc6d7f39 to your computer and use it in GitHub Desktop.
Catch exceptions
while True:
try:
subtrack = int(input("Enter a digit between 1 and 10 to subtract: "))
if subtrack < 0:
print("Please enter a positive number")
continue
elif 0 < subtrack <= 10:
break
else:
print("Please enter a number between 1 and 10")
continue
except ValueError:
print("Please enter a valid number")
while True:
try:
subtract = int(input("Enter a digit between 0-10 to subtract: "))
if subtract < 0 or subtract > 10:
print("Incorrect entry. Try again")
continue
break
except ValueError:
print("Please enter a valid number")
while True:
try:
start = int(input("Enter a digit greater than " + str(subtract) + " to start: "))
if start <= subtract:
print(start, "is not greater than", subtract, "!")
continue
break
except ValueError:
print("Please enter a valid number")
print("Starting the countdown from", start)
while True:
start = start - subtract
print("The next number is:", start)
if start <= 0:
print("The countdown is over!")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment