|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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,而不能用str 或者 int 类型呢?
之所以使用 float 而不使用 int 是因为 利润 可能存在小数,比如说5角3分
然后不适用 str 的原因是,input 默认本身就是 str 根本不需要转换成 str,但是此处必须使用 float 是因为 str 不能和 float 也就是 0.1 0.075 100000 等 int 或 float 类型直接加减乘除,会出现报错
|
|