Question

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 Rate: nine

Error, please enter numeric input

Enter Hours: forty

Error, please enter numeric input

Rewrite your code to validate the inputs and keep asking the user to enter valid inputs for the hours and the rate value.

So:

  1. Ask the use for their company name
  2. Ask the use for the hours they work in a week
  3. Ask the use for the rate (dollar/hour)
  4. Check user inputs
  5. Do it in a loop
  6. strip the inputs => use strip()
  7. Only display 2 decimal points when displaying all the numbers. => use round(theOutput,2)
  8. Print the company's name, the hours, the rate and the gross pay, and also a random number between 1000 to 2000 for their document numbers.

Example output:

Enter your company name: Google

Enter the hours: 45

Enter the rate: 10

Print the company's name, the hours, the rate and the gross pay, and also a random number between 1000 to 2000 for their document numbers.

Company: Google

hours: 45

Rate: 10

**********************************************

Your document number is: 1585

Your Google gross pay is 475 dollars.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below::::

import random
companyName = input("Enter your company name : ").strip()
while True:
try:
hours = int(input("Enter the hours : ").strip())
break
except:
print("Error!!! please enter numeric input")
  

while True:
try:
pay = float(input("Enter the rate : ").strip())
break
except:
print("Error!!! please enter numeric input")
  
print("Company : "+companyName)
print("Hours : "+str(hours))
print("Rate : "+str(round(pay,2)))
print("***************************************")
print("Your document number is :"+str(random.randint(1000,2000)))
if hours<40:
totalPay = hours*pay
else:
totalPay = 40*pay + (hours-40)*pay*1.5
  
print("Your Google gross pay is "+str(round(totalPay,2))+" dollars.")

Add a comment
Know the answer?
Add Answer to:
It's my python assignment. Thank you You wrote a program to prompt the user for hours...
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
  • 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:...

  • (Java) Rewrite the following exercise to check the user inputs to be: Valid input and positive...

    (Java) Rewrite the following exercise to check the user inputs to be: Valid input and positive with using try-catch (and/or throw Exception ) ************************************************************************** Write a program to prompt the user for hours and rate per hour to compute gross pay. Calculate your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours. Your code should have at least the following methods to calculate the pay. (VOID and NON-STATIC) getInputs calculatePay printPay Create...

  • (Java) Rewrite the following exercise below to read inputs from a file and write the output...

    (Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...

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

  • Data Programming l: PYTHON 1. Write a program that computes your gross pay. Your code should...

    Data Programming l: PYTHON 1. Write a program that computes your gross pay. Your code should get two numbers: hours and rate per hour. You should give the employee 1.75 times the hourly rate for hours worked above 40 hours. Output: Your gross pay is $487.5 2. Rewrite the previous program using try and except so that your program handles non-numeric inputs gracefully by printing a message and exiting the program. The following shows two executions of the program with...

  • This is a Java beginner class. Write the following exercise to check the user inputs to...

    This is a Java beginner class. Write the following exercise to check the user inputs to be: Valid input and positive with using try-catch (and/or throw Exception ) ************************************************************************** Write a program to prompt the user for hours and rate per hour to compute gross pay. Calculate your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours. Your code should have at least the following methods to calculate the pay. (VOID and...

  • Please help me to do my assignment it should be python. Thank you Write a menu-driven...

    Please help me to do my assignment it should be python. Thank you Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until he/she chooses...

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

  • Styles Program Description Write a C++ program that computes and displays employees' earnings. Prompt the user...

    Styles Program Description Write a C++ program that computes and displays employees' earnings. Prompt the user for type of employee (hourly ("h"or "H") or management ("'m" or "M") If the employee is management: . get the annual salary get the pay period (weekly ("w" or "W"), bi-weekly ("b" or "B") or monthly ("m" or e compute the gross salary for the pay period (Divide annual salary by 52 for weekly, 26 for bi-weekly, and 12 for monthly) deduct from gross...

  • Create a payroll program named CalcPay that allows the user to enter two double valuesand a...

    Create a payroll program named CalcPay that allows the user to enter two double valuesand a string namely hours worked, hourly rate and name. After the user enters the rate, hours,and name the program should calculate the gross pay. Compute federal withholding tax which is subtracted from gross based on the following table: Hints: (100pts) Use methods as deemed appropriate. 0 to 99.99 6% 100.00 to 299.99 12% 300.00 to 599.99 18% 600.00 and up 21%. Display the output. The...

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