Question

The rule will be for hours up to 40, calculate pay using the rate entered; for...

  1. The rule will be for hours up to 40, calculate pay using the rate entered; for any hours above 40, calculate pay as (1.5 * rate).
    • Name your function to compute pay (hours, rate) and use the function to do the computation.
    • You still want to prompt the user for hours and rate OUTSIDE of your function. Name these variables "h" for hours, and "r" for rate:

      h = float(input('How many hours?: '))
      r = float(input('What is your hourly rate?: '))
    • Put your function at the top of your page (right below your name / date comment), then get input from the user as outlined above, and call the function and print the gross pay returned by the function.
      • Note that you will RETURN the gross pay from the function and print it; DO NOT print the gross pay from within the function. Something like this:

        grosspay = computepay(h, r)

        Where h and r would be the hours and rate float() values entered by the user (see above). Again, DO NOT print the value within the function; I don't want to see this:
        def computepay(hours, rate):
        
             print(hours*rate)
    • You will need to use a conditional block within the function; if hours worked is less than or equal to forty, then you will only calculate/return hours * rate. If hours worked is greater than forty, then the math would be (rate*40) + (1.5*rate*hours over forty)
    • Once you have everything put together, make sure to perform two tests; 1) hours worked is over 40, and 2) hours worked is under 40. This way both conditions in the function will run.
    • You should use input() to read a string and float() to convert the string to a number as shown above. Do not worry about error checking the user input unless you want to - you can assume the user types numbers properly.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#source code:

def computepay(h,r):
   if(h<=40):
       return h*r
   else:
       return (r*40)+(1.5*r*h)
if __name__=="__main__":
   h = float(input('How many hours?: '))
   r = float(input('What is your hourly rate?: '))
   grosspay = computepay(h, r)
   print(grosspay)

1 2 انبا def computepay (h, r): if(h<=40): return h*r else: return (r*40)+(1.5*r*h) if main h float(input(How many hours?:

#if you have any doubt or more information needed comment below...i will respond as possible as soon...thanks...

Add a comment
Know the answer?
Add Answer to:
The rule will be for hours up to 40, calculate pay using the rate entered; for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program to prompt the user for hours and rate per hour using input to...

    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...

  • It's my python assignment. Thank you You wrote a program to prompt the user for hours...

    It's my python assignment. Thank you You wrote a program to prompt the user for hours and rate per hour to compute gross pay. Also your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours. Enter Hours: 45 Enter Rate: 10 Pay: 475.0 (475 = 40 * 10 + 5 * 15) Rewrite your pay program using try and except so that your program handles non-numeric input gracefully. Enter Hours: 20 Enter...

  • using c++ output format should look this but use employee id,hours worked and pay rate and...

    using c++ output format should look this but use employee id,hours worked and pay rate and the total should be calculated. for example employee id:1234 hours work:29.3 pay rate:16.25 administrative, office and field should be outputted as well too. Using a structure, and creating three structure variables, write a program that will calculate the total pay for thirty (30) employees. (Ten for each structured variable.) Sort the list of employees by the employee ID in ascending order and display their...

  • This is my python assignment You wrote a program to prompt the user for hours and...

    This is my python assignment You wrote a program to prompt the user for hours and rate per hour to compute gross pay. Also your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours. Enter Hours: 45 Enter Rate: 10 Pay: 475.0 (475 = 40 * 10 + 5 * 15) Rewrite your pay program using try and except so that your program handles non-numeric input gracefully. Enter Hours: 20 Enter Rate:...

  • PYTHON Write a function called hourly_employee_input that asks the user for a name (string), hours worked...

    PYTHON Write a function called hourly_employee_input that asks the user for a name (string), hours worked (int) and an hourly pay rate (float) and prints a string including the information. Call the function, entering expected values, numbers in appropriate range Call the function, entering negative numbers Call the function, entering bad input (letters, symbols) What do you need to add to your function for bad input? Handle the bad input so your program doesn't end when receiving bad input

  • A) One of the problems that have been discussed in the class is to write a...

    A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following: int main() { double radius; double area; double circumference; //the radius...

  • Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All...

    Why is my code not calculating the pay and not printing entire data at the end? // // main.cpp // Project 14 // // Created by Esmeralda Martinez on 5/13/19. // Copyright © 2019 Esmeralda Martinez. All rights reserved. // #include<iostream> #include<fstream> #include<cstdlib> #include<regex> #include <iomanip> using namespace std; float grossPay(float hrsWorked, float payrate); float grossPay(float hrsWorked, float payrate){ return hrsWorked*payrate;       } int main(){    //opening an output file ifstream outFile("Employee.txt", ios::in); //Read variables string depId,emp_num,firstName,lastName,email,hrs_worked,pay_rate,ch="y";    //Regex patterns regex integerPattern("(\\+|-)?[[:digit:]]+"); regex...

  • Exercise 1 A program was created that outputs the following unto the console: Hello! What is...

    Exercise 1 A program was created that outputs the following unto the console: Hello! What is your name: Hello, Jane Doe! Using this program, we can help you determine you pay for the week! Please enter the hours you worked this week: 20 Next, please enter your rate of pay: 10 Calculating… you will make $ 200 by the end of the week! Here is the code for that program (you should have written a close variant of this last...

  • A) One of the problems that have been discussed in the class is to write a simple C++ program to ...

    C++ programming question will upvote A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...

  • If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly...

    If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly pay) If the employee is not a supervisor and she worked 40 hours or less calculate her paycheck as her hourly wage * hours worked (regular pay) If the employee is not a supervisor and worked more than 40 hours calculate her paycheck as her (hourly wage * 40 ) + (1 ½ times here hourly wage * her hours worked over 40) (overtime...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT