Last active
May 30, 2020 23:47
-
-
Save jmangrad/82d517bca5df05ad5eab72c8fd97c65e 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
Rewrite your pay program using try and except so that your | |
program handles non-numeric input gracefully by printing a message | |
and exiting the program. The following shows two executions of the | |
program: | |
Enter Hours: 20 | |
Enter Rate: nine | |
Error, please enter numeric input | |
Enter Hours: forty | |
Error, please enter numeric input | |
hours = input("Enter hours worked: ") # asks user for hours worked for the week | |
try: | |
hours = int(hours) | |
rate = input("Enter how much you earn per hour: ") # asks user how much per hour they get paid | |
try: | |
rate = float(rate) | |
if hours > 40: | |
pay = (1.5 * rate * (hours -40) + (40 * rate)) | |
print(pay) | |
else: | |
pay = rate * hours | |
print(pay) | |
except: | |
print("Error, please enter a numerica value") | |
except: | |
print("Error, please enter a numerica value") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment