Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking the user input unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.
Question
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking the user input unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.
Solution
Here is a Python program that follows the instructions given:
def computepay(hours, rate):
if hours > 40:
overtime = hours - 40
else:
overtime = 0
normal_hours = hours - overtime
pay = (normal_hours * rate) + (overtime * rate * 1.5)
return pay
hours = float(input("Enter Hours:"))
rate = float(input("Enter Rate:"))
pay = computepay(hours, rate)
print('Pay:', pay)
You can run this program and enter 45 for hours and 10.50 for rate to test it. The output should be 498.75.
Similar Questions
An employee will have a name, pay_rate, and list of hours_worked.Employee class must have following methods:Constructor – takes name and pay_rate. It will also creat an empty list of hours_worked.add_hours – takes hours as a parameter and add it to the hours_worked list.salary – calculates the salary for the employe (pay_rate x total hours worked).Write a main function that will:Ask user for employee name and pay rate.Create the employee object.Ask user for the number of days the employee worked.For each day it will ask the user for number of hours that employee worked and use the add_hours function to add this to the list of hours_worked in employee class.It will display the employee data as follows (use f string to format the output):Employee Name: Joe DoePay Rate: $ 25.75 per hourTotal number of hours worked: 39.45Total Salary: $ 1015.84
Ask user for employee name and pay rate.Create the employee object.Ask user for the number of days the employee worked.For each day it will ask the user for number of hours that employee worked and use the add_hours function to add this to the list of hours_worked in employee class.It will display the employee data as follows (use f string to format the output):Employee Name: Joe DoePay Rate: $ 25.75 per hourTotal number of hours worked: 39.45Total Salary: $ 1015.84
Create a Java base class called Employee. Use this class to store two double-type values that could be used to compute the salary of employees. Also,the base class should have a static variable ‘totalemp’ to keep track of the total number of employees created. Derive two specific classes called part_time and full_time from the base employee. Add a member function called as get_basic() to get the basic pay and another member called display_salary() to compute and display the salary of the employees. Using these three classes, design a program that will accept the basic pay of part_time and full_time employees interactively. Remember the two values given as input will be treated as the basic pay of the employees and the following information is used for calculating the salaries of both the part-time as well as full-time employees. Print invalid if the basic_salary of part-time employee and basic_salary of full-time employee are not met the ”Boundary Condition”Part time Full timeHRA = 20% of basic pay HRA = 30% of basic payDA = 72% of basic pay DA = 80% of basic paySalary = Basic + HRA + DA Salary = Basic + HRA + DABoundary Condition:0 < basic_salary of part-time employee <= 10000000 < basic_salary of full-time employee <= 1000000Input Format:First line to enter the basic_salary of part-time employee and basic_salary of full-time employeeOutput Format:Total salary of part-time employee and total salary of full-time employee.Total number of employees processed Sample Testcase Input-1:50007000000Sample Testcase Output-1:8900.0invalid1 Sample Testcase Input-2:30000600000Sample Testcase Output-2:42720.0110400.02 Sample Testcase Input-3:0900000Sample Testcase Output-3:invalid216000.01
Jonas is paid $17$17 per hour and gets paid a bonus of $65$65 each week. One particular week he earned $643$643.a.Define a pronumeral for the number of hours Jonas worked.- WorkspaceType Draw Upload↕+ Check answerb.Write an equation to describe the problem.+ Workspace+ Check answerc.Solve the equation algebraically.+ Workspace+ Check answerd.How many hours did Jonas wor
James works a basic week of 40 hours and has an hourly rate of pay of $19.50.Calculate his weekly wage before tax.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.