Exercise 6: Rewrite your pay computation with time-and-a-half for overtime and create a function called computepay which takes two parameters (hours and rate).
Enter Hours: 45
Enter Rate: 10
Pay: 475.0
inp_hours = input("Enter hours: ")
try:
fl_hours = float(inp_hours)
inp_rate = input("Enter Rate: ")
fl_rate = float(inp_rate)
except:
print("Error, please enter numeric input")
quit()
def computepay(hours, rate):
if hours <= 40:
pay = hours * rate
elif hours > 40:
pay = (40 * rate) + ((hours - 40) * (rate * 1.5))
print("Pay: ", pay)
computepay(fl_hours, fl_rate)
Exercise 7: Rewrite the grade program from the previous chapter using a function called computegrade that takes a score as its parameter and returns a grade as a string.
Score Grade
>= 0.9 A
>= 0.8 B
>= 0.7 C
>= 0.6 D
< 0.6 FAIL
Enter score: 0.95
A
Enter score: perfect
Bad score
Enter score: 10.0
Bad score
Enter score: 0.75
C
Enter score: 0.5
FAIL
Run the program repeatedly to test the various different
values for input.
inp_score = input("Enter score: ")
try:
fl_score = float(inp_score)
except:
print("Bad score")
quit()
def computegrade(score):
try:
if score > 0 and score <= 1:
if score >= 0.9 and score <= 1:
print("A")
elif score >= 0.8:
print("B")
elif score >= 0.7:
print("C")
elif score >= 0.6:
print("D")
elif score < 0.6:
print("FAIL")
else:
print("Bad score")
except:
print("Bad score")
computegrade(fl_score)