calculate gross pay in python

Solutions on MaxInterview for calculate gross pay in python by the best coders in the world

showing results for - "calculate gross pay in python"
Federico
30 Mar 2019
1def weeklyPay(hours, wage):
2    if hours > 40:
3        return 40 * wage + (hours - 40) * wage * 1.5
4    else:
5        return hours * wage
6 
7def getFloat(prompt):
8    while True:
9        try:
10            return float(input(prompt))
11        except ValueError:
12            print("This is an invalid value. Try again. ")
13 
14hours = getFloat("How many hours did you work? ")
15wage = getFloat("What was your hourly rate? ")
16 
17pay = weeklyPay(hours, wage)
18 
19print(f"Total pay: ${pay:.2f} ")
20