如何解决这个“无法解决的类型”错误

时间:2016-09-18 19:57:59

标签: python if-statement

我一直收到以下错误,我的程序无法运行。我需要确保我的程序是模块化的,并使用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()

Error Message

1 个答案:

答案 0 :(得分:1)

您应该将hourspayRate转换为整数或浮点数,如下所示:

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: "))

取决于您是否只想包含自然数字或小数点后的数字.