Computer Science, asked by vinayaksoni82, 7 months ago

Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Use 35 hours and a rate of 2.75 per hour to test the program (the pay should be 96.25). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking or bad user data. please explain it ?

Answers

Answered by MrUnstoppable
4

The below code is written in python,

def computepay(workhour,workrate):

hours = input("Enter Hours of work:")  // enter the hours in string

workhour = float(hours)  //converting the string into float

rate = input("Enter Rate of work:")  //enter the rate in string

workrate = float(rate) //converting the string into float

pay = ( workhour * workrate )

//if-else loop starts with the mentioned condition

if workhour <= 40 :  

return(pay)

else :

overhours = (workhour-40)

regular = (workrate*40)

others = overhours * (workrate *1.5)

overpay = (regular + others)

return(ovrpay)

print(computepay(45,10.5))

Answered by Equestriadash
8

choice = "Yes"

while choice == "Yes":

   h = input("Enter the number of hours: ")

   hours = float(h)

   r = input("Enter the rate per hour: ")

   rate = float(r)

   gp = hours*rate

   print()

   print(gp, "is your gross pay.")

   print()

   choice = input("Would you like to check for a new person? [Yes/No]: ")

   print()

When converting a string value to a float value, it's important that another variable is used to store it's conversion.

I've used a while loop as well, that repeatedly runs the program if the user wishes to do so.

Similar questions