我一直收到以下错误,我的程序无法运行。我需要确保我的程序是模块化的,并使用if-then
语句来确定要使用的总薪酬等式。
BASE_HOURS = 40
OT_MULTIPLIER = 1.5
def main():
hours = input("Enter the number of hours worked: ")
payRate = input("Enter the hourly pay rate: ")
calcPayWithOT(hours,payRate)
def calcPayWithOT(hours,payRate):
if hours <= BASE_HOURS:
theGrossPayNoOT = hours * payRate
print("The gross pay is $ ", theGrossPayNoOT)
if hours > BASE_HOURS:
theGrossPayOT = (hours - BASE_HOURS) * OT_MULTIPLIER + (hours * payRate)
print("The gross pay is $ ", theGrossPayOT)
main()
答案 0 :(得分:1)
您应该将hours
和payRate
转换为整数或浮点数,如下所示:
hours = int(input("Enter the number of hours worked: "))
payRate = int(input("Enter the hourly pay rate: "))
或
hours = float(input("Enter the number of hours worked: "))
payRate = float(input("Enter the hourly pay rate: "))
取决于您是否只想包含自然数字或小数点后的数字.