Python Program to Calculate Weekly Pay

Posts 1–2 of 2 · Page 1 of 1
Python Program to Calculate Weekly Pay
Coded in IDLE. Program asks the user to input their hourly wage, how many regular hours they worked for the week (<=40) and the amount of over time hours (>40). Program automatically calculates the over time pay rate (most places it is 1.5x the regular pay). It then outputs how much you made for the week.
Code:
variable_hourlyWage = float(input('What is your hourly wage? ')) #hourly wage input
variable_regHours = float(input('How many regular hours this week? ')) #regular hours input
variable_overtimeHours = float(input('How many over time hours this week? ')) #overtime hours input
variable_overtimePay = variable_hourlyWage * 1.5 #formula for overtime pay
variable_weeklyPay = (variable_hourlyWage * variable_regHours) + (variable_overtimeHours * variable_overtimePay) #formula for weekly pay

print('You have made', '$' + str(variable_weeklyPay))
Nice beginner Python project. The code is simple and easy to understand. One small improvement could be adding input validation to make sure the user doesn't enter negative hours or invalid values. Also, formatting the final output with two decimal places would make it look cleaner for money values.
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us