014作业自己动手出现问题
temp = input("请输入今年的利润:")guess = float(temp)
if guess <= 100000:
print("应该发放的奖金总数是:",guess * 10%)
elif 100000 < guess < 200000:
print("应该发放的奖金总数是:",(guess - 100000) * 7.5% + 1000)
elif 200000 < guess < 400000:
print("应该发放的奖金总数是:",(guess - 200000) * 5% + 1750)
elif 400000 < guess < 600000:
print("应该发放的奖金总数是:",(guess - 400000) * 3% + 11750)
elif 600000 < guess < 100000:
print("应该发放的奖金总数是:",(guess - 600000) * 1.5% + 17750)
else:
print("应该发放的奖金总数是:",(guess - 1000000)* 1% + 23750)
不知道到底哪里出错了 10%。。。
应该没有这个用法,改成小数吧0.1
其它也一样 本帖最后由 jackz007 于 2021-3-14 01:43 编辑
if guess <= 100000:
print("应该发放的奖金总数是:",guess * 0.1 )# 10% 错误表达,应该写成 0.1
elif 100000 < guess <= 200000:
print("应该发放的奖金总数是:",(guess - 100000) * 7.5% + 1000)
elif 200000 < guess <= 400000:
print("应该发放的奖金总数是:",(guess - 200000) * 5% + 1750)
elif 400000 < guess <= 600000:
print("应该发放的奖金总数是:",(guess - 400000) * 3% + 11750)
elif 600000 < guess <= 1000000:
print("应该发放的奖金总数是:",(guess - 600000) * 1.5% + 17750)
else:
print("应该发放的奖金总数是:",(guess - 1000000)* 1% + 23750)
if 语句如果不把 < 改为 <= 那么,就会漏掉 guess == 200000、400000、600000、1000000,逻辑条件就会出现漏洞。 10%那个地方,没有这种写法。把百分数全改成小数就可以啦
我写的,将就着看哈{:10_297:}#年终奖
money = int(input('请输入今年的利润:'))
prize = 0
if money <=100000:
prise = money * 0.1
elif 100000 < money < 200000:
prize = 1000 + (money - 100000) * 0.075
elif 200000 <= money < 600000:
if money < 400000:
prize = 1750 + (money - 200000) * 0.05
else:
prize = 11750 + (money - 400000) * 0.03
elif 600000 <= money < 1000000:
prize = 17750 + (money - 600000) * 0.015
else:
prize =23750 + (money - 1000000) * 0.01
print('应该发放的奖金总数是:%.1f' %prize)
页:
[1]