This program will be ran through a Python 3 IDE. Write function pay() that takes
ID: 3680407 • Letter: T
Question
This program will be ran through a Python 3 IDE.
Write function pay() that takes as input an hourly wage and the number of hours an employee worked in the last week. The function should compute and return the employee's pay. Overtime work should be paid in this way: Any hours beyond 40 but less than or equal to 60 should be paid at 1.5 times the regular hourly wage. Any hours beyond 60 should be paid at 2 times the regular hourly wage.
Here is an example of how the function should work:
>>> pay(10, 35)
350
>>> pay(10, 45)
475.0
>>> pay(10, 61)
720.0
Explanation / Answer
Note Calculation of pay function example output is wrongly printed for pay(10,45) is 675 and for pay(10,61) is 1220
NOTE FOR PYTHON USE TABS OR PROPERALLIGNMENT OF CODE IS MANDATORY OTHER WISE PROGRAM CAUSES ERROR
main.py
def pay(hourly_sal,no_of_hours):#function definition
if no_of_hours <= 40:#ifelse statement syntax in python
print(hourly_sal*no_of_hours)#if noofhours less than 40
elif no_of_hours <= 60:
print(hourly_sal*1.5*no_of_hours)#if noofhours>40noofhours<=60
elif no_of_hours > 60:
hourly_sal=hourly_sal*2
print(hourly_sal*no_of_hours)#noofhours>60
pay(10,35)#function calling
pay(10,45)#function calling
pay(10,61)#function calling
OUTPUT
sh-4.3$ python main.py
350
675.0
1220
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.