FOR PYTHON
Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay which takes two parameters (hours and rate).
Enter Hours: 45
Enter Rate: 10
Pay: 475.0
YOU WILL NEED THREE FUNCTIONS:
the_hours, the_rate = get_input()
the_pay = compute_pay(the_hours, the_rate)
print_output(the_pay)
Call the functions and passing the arguments in the "main" function.
Example:
def main():
the_hours, the_rate = get_input()
the_pay = compute_pay(the_hours, the_rate)
print_output(the_pay)
main()
-----
Python program :
#python function to get input from user def get_input(): hours=0 #declaring variable to store hours rate=0 #declaring variable to store rate while hours<=0 or rate<=0: hours=int(input("Enter Hours : ")) #asking user hours rate = int(input("Enter Rate : ")) #asking user rate return hours,rate #return hours and rate #function to compute_pay def compute_pay(the_hours, the_rate): pay=0 #declaring variable to store pay #checking the_hours if the_hours<=40:#when the_hours is less than or equal to 40 pay=the_hours*the_rate #calculate pay elif the_hours>40:#when the hours is greater than 40 pay=40*the_rate+(the_hours-40)*the_rate*1.5 return pay #function to print pay def print_output(the_pay): print("Pay:",the_pay) #main() function definition def main(): the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) #call to main() function main()
********************************
============================
Screen 1:Screen when hours are greater than 40
Screen 2:Screen when hours are less than 40
Get Answers For Free
Most questions answered within 1 hours.