【发布时间】:2021-05-28 01:34:32
【问题描述】:
我是 python 新手,在我鼓起的一个练习程序上有点挣扎。
目标:
如果数量为 100 件或更少,则每件成本为 350 美元。
如果数量为 200 件或更少,前 100 件的价格为 350 美元,不限 不到 200,但超过 100 的成本是 $300。
如果数量为 200 件或更多,前 100 件售价 350 美元,下一件 100 件要 300 美元,200 件以上要 250 美元。
计算总订单的价格。
quantities = [84, 100, 126, 150, 186, 200, 216, 248]
cost = 0
for i in range(len(quantities)):
if quantities[i] <= 100:
cost = (quantities[i] * 350)
print(f"The cost for an order of {quantities[i]} is ${cost}.")
elif quantities[i] >= 100 and quantities[i] <= 200:
cost = cost + (quantities[i] * 300)
print(f"The cost for an order of {quantities[i]} is ${cost}.")
elif quantities[i] >= 200:
cost = cost + (quantities[i] * 250)
print(f"The cost for an order of {quantities[i]} is ${cost}.")
我得到的答案:
The cost for an order of 84 is $29400.
The cost for an order of 100 is $35000.
The cost for an order of 126 is $72800.
The cost for an order of 150 is $117800.
The cost for an order of 186 is $173600.
The cost for an order of 200 is $233600.
The cost for an order of 216 is $287600.
The cost for an order of 248 is $349600.
我应该得到的答案:
The cost for an order of 84 is $29400.
The cost for an order of 100 is $35000.
The cost for an order of 126 is $42800.
The cost for an order of 150 is $50000.
The cost for an order of 186 is $60800.
The cost for an order of 200 is $65000.
The cost for an order of 216 is $69000.
The cost for an order of 248 is $77000.
Where am I going wrong in my calculation?
【问题讨论】:
标签: python