这个代码为什么不对?
下面这个是我写的代码,执行不了,想知道为什么(答案是需要用到floatimport decimal
n = int(input("请输入今年的利润:"))
if n <= 100000:
m = n * decimal.Decimal('0.1')
elif 100000 <= n < 200000:
m = 10000 + (n - 100000) * decimal.Decimal('0.075')
elif 200000 <= n < 400000:
m = 17500 + (n - 200000) * decimal.Decimal('0.05')
elif 400000 <= n < 600000:
m = 27500 + (n - 400000) * decimal.Decimal('0.03')
elif 600000 <= n < 1000000:
m = 45500 + (n - 600000) * ('0.015')
else:
m = 51500 + (n - 1000000) * ('0.01')
print(m)
下面两个忘记写 decimal.Decimal() 了import decimal
n = int(input("请输入今年的利润:"))
if n <= 100000:
m = n * decimal.Decimal('0.1')
elif 100000 <= n < 200000:
m = 10000 + (n - 100000) * decimal.Decimal('0.075')
elif 200000 <= n < 400000:
m = 17500 + (n - 200000) * decimal.Decimal('0.05')
elif 400000 <= n < 600000:
m = 27500 + (n - 400000) * decimal.Decimal('0.03')
elif 600000 <= n < 1000000:
m = 45500 + (n - 600000) * decimal.Decimal('0.015')
else:
m = 51500 + (n - 1000000) * decimal.Decimal('0.01')
print(m)
页:
[1]