我看了半天没想出来,书都翻烂了,都找不到😭,请各位解答一下这个问题。
程序不知道这个x是做什么的啊,if 代码前面加一个 for x in range(len(c)),另外c跟d的元素应该是一致的吧 是不是cd的数据弄错了
a = int(input("show me the profit:"))
b = 0
c = [100000,100000,200000,200000,400000]
d = [0.1,0,0.75,0.05,0.03,0.015,0.01]
for x in range(len(c)):
if a <= c[x]:
b += a*d[x]
a = 0
else:
b += c[x]*d[x]
b -= c[x]
b += a*d[-1]
print(b)
外边少了一层for循环吧:
for x in range(5):
a = int(input("show me the profit:"))
b = 0
c = [100000, 100000, 200000, 200000, 400000]
d = [0.1, 0, 0.75, 0.05, 0.03, 0.015, 0.01]
for x in range(5):
if a <= c[x]:
b += a * d[x]
a = 0
else:
b += c[x] * d[x]
b -= c[x]
b += a * d[-1]
print(b)