第一行这里为什么要用float,用int是不是也是一样的效果
profit = float(input("请输入今年的利润:"))if profit <= 100000:
reward = profit * 0.1
elif 100000 < profit <= 200000:
reward = 100000 * 0.1 + (profit - 100000) * 0.075
elif 200000 < profit <= 400000:
reward = 100000 * 0.1 + 100000 * 0.075 + (profit - 200000) * 0.05
elif 400000 < profit <= 600000:
reward = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (profit - 400000) * 0.03
elif 600000 < profit <= 1000000:
reward = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (profit - 600000) * 0.015
else:
reward = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (profit - 1000000) * 0.01
print("应该发放的奖金总数是:", reward, sep='') 鱼油你好!
第一行用float是因为利润很可能包含小数。比如“12345.67”元,用int无法转换,会报错;而float可以正确处理。即使输入是整数,float也能得到小数形式(如123.0),不影响后续计算。所以用float更通用。
profit = float(input("请输入今年的利润:"))
if profit > 0:
print("盈利")
如果你确定利润永远是整数,用int也不是不行,但一旦遇到小数就会出错。因此推荐使用float。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 float是浮点数,int是整数
页:
[1]