# Exceptions using try: and catch: try:     # Input Section     hours = float(input('Enter Hours: \n'))     ''' Your code to input rate here '''     # Processing Section     if (hours > 40):         ''' Your code to compute regular_pay '''         ''' Your code to compute overtime_pay '''         ''' Your code to compute gross_pay '''     else:         ''' Your code to compute regular_pay '''         ''' Your code to compute overtime_pay '''         ''' Your code to compute gross_pay '''     # Output Section

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 15SA
icon
Related questions
Question

# Exceptions using try: and catch:
try:
    # Input Section
    hours = float(input('Enter Hours: \n'))
    ''' Your code to input rate here '''

    # Processing Section
    if (hours > 40):
        ''' Your code to compute regular_pay '''
        ''' Your code to compute overtime_pay '''
        ''' Your code to compute gross_pay '''
    else:
        ''' Your code to compute regular_pay '''
        ''' Your code to compute overtime_pay '''
        ''' Your code to compute gross_pay '''

    # Output Section
    ''' Your code to output gross_pay with 2 decimals '''

except:
    print('Error, please enter numeric input')

4.22 LAB: Gross Pay with Overtime and try/except
(1) Rewrite your gross_pay computation to give the employee 1.5 times the hourly rate for hours Worked above 40 hours. That is, if
hours is greater than 40, assign regular_pay 40 times rate, then assign overtime_pay 1.5 times rate times the difference in the
hours over 40. Otherwise, compute the pay as before
Ex:
Enter Hours: 45
Enter Rate: 10.75
Pay: $510.62
(2) Rewrite your pay program above 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:
Ex:
Enter Hours: 20
Enter Rate: nine
Error, please enter numeric input
Enter Hours: fifty
Error, please enter numeric input
Transcribed Image Text:4.22 LAB: Gross Pay with Overtime and try/except (1) Rewrite your gross_pay computation to give the employee 1.5 times the hourly rate for hours Worked above 40 hours. That is, if hours is greater than 40, assign regular_pay 40 times rate, then assign overtime_pay 1.5 times rate times the difference in the hours over 40. Otherwise, compute the pay as before Ex: Enter Hours: 45 Enter Rate: 10.75 Pay: $510.62 (2) Rewrite your pay program above 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: Ex: Enter Hours: 20 Enter Rate: nine Error, please enter numeric input Enter Hours: fifty Error, please enter numeric input
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning