为什么我总是得到这个答案? TypeError:第8行Sub:'str'和'int'的操作数类型不受支持
#Define payment, knowing that up to 40 hours it is normal rate, and above that every hour is paid at 150%.
totalHours = input("Enter the total amount of worked hours:\n")
hourlyWage = input("Enter the payrate per hour:\n")
if totalHours <= 40:
regularHours = totalHours
overtime = 0
else:
overtime = float(input(totalHours - 40))
regularHours = float(input(40))
payment = hourlyWage*regularHours + (1.5*hourlyWage)*overtime
print (payment)
您需要添加
int
转换。你知道吗从
input
得到的是str
而不是int
,因此不能用str
和int
进行数学运算。你知道吗在python3中,如果您提供输入,它只接受字符串形式的输入。你需要把它转换成int。另外,else部分的输入是不必要的
相关问题 更多 >
编程相关推荐