我刚刚写了一个程序来计算员工的工资率。对我来说,该程序看起来还不错,但是当我尝试运行它时,我会重新启动,但它没有运行。我试过重新启动 Python GUI,但没有运气。这是程序:
def get_info():
hours = int(input("How many hours did you work this week?", ))
while hours < 8 or hours > 86:
print('Error ---- you must work at least 8 hours and no more than 86 hours')
hours = int(input('Please enter your hours worked again:', ))
print()
rate = float(input("Please enter your pay rate: $", ))
while rate < 7.00 or rate > 50.00:
print("Error ---- pay rate cannot be less than $7.00 or greater than $50.00")
rate = float(input("Please re-enter your pay rate: $", ))
return hours, rate
def calc_hours(num):
if num < 40:
reg_hours = num
overtime = 0
else:
reg_hours = 40
overtime = num - 40
return reg_hours, overtime
def calc_pay(num1, num2, pay_rate):
regular_pay = num1 * pay_rate
overtime_pay = num2 * (pay_rate * 1.5)
total_pay = regular_pay + overtime_pay
return regular_pay, overtime_pay, total_pay
def main():
get_info()
calc_hours(hours)
cal_pay(reg_hours, overtime, rate)
print ()
print (" Payroll Information")
print ()
print ("Pay Rate", format(rate, '14.2f'))
print ("Regular Hours", format(reg_hours, '10.2f'))
print ("Overtime Hours", format(overtime, '10.2f'))
print ("Regular Pay", format(regular_pay, '10.2f'))
print ("Overtime Pay", format(overtime_pay, '10.2f'))
print ("Total Pay", format(total_pay, '10.2f'))
是的,图表会很不稳定。我一直没能成功运行它,所以它会顺利出来。