Exercise 3.2: Rewrite your pay program using try and except so that your
program handles non-numerical 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
Python for Everybody: Exploring Data Using Python 3
by Charles R. Severance
hours = float(hours)
rate = input("Enter Rates: ")
if hours > 40 :
rate = float(rate)
pay = round((40 * rate) + ((hours-40) * rate * 1.5), 2)
print("Pay: ", pay)
else :
rate = float(rate)
pay = hours * rate
print("Pay: ", pay)
except:
print("Error! please enter numeric input")
'PYTHON' 카테고리의 다른 글
Answer (5-01) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |
---|---|
Answer (4-07) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |
Answer (4-06) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |
Answer (3-03) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |
Answer (3-01) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |