这是我目前的密码。请注意,“percentageOff”和“originalPrices”是带有浮点数/整数的列表。你知道吗
print("Percent off:", percentageOff[0], '%')
for percentage in percentageOff[1:]:
print("\t\t\t", percentage, "%")
count = 0
for prices in originalPrices:
for percentage in percentageOff:
discount = prices * (percentage/100)
newPrice = prices - discount
count += 1
if(0 < count < 11):
print("%.2f" % newPrice)
elif(11 < count < 21):
print("\t\t\t%.2f" % newPrice)
输出是(与代码的其余部分一起):
**Sale Prices**
Normal Price: $9.95 $14.95 $19.95 $24.95 $29.95 $34.95 $39.95 $44.95 $49.95
______________________________________________________________________________________
Percent off: 5 %
10 %
15 %
20 %
25 %
30 %
35 %
40 %
45 %
50 %
9.45
8.96
8.46
7.96
7.46
6.96
6.47
5.97
5.47
4.97
但我希望输出是
**Sale Prices**
Normal Price: $9.95 $14.95 $19.95 $24.95 $29.95 $34.95 $39.95 $44.95 $49.95
______________________________________________________________________________________
Percent off: 5 % 9.45
10% 8.96
15% 8.46
20% 7.96
25% 7.46
30% 6.96
35% 6.47
40% 5.97
45% 5.47
50% 4.97
我怎样才能解决我的问题?你知道吗
取决于@danidee
输出为
我建议最好使用python格式化程序! 假设您使用的是python3,代码可以这样重新排列(注释很好,希望不需要额外的解释):
这将产生如下输出:
希望有帮助。你知道吗
不使用外部库的最佳解决方案是将不同的值放入列表中,同时对它们进行迭代和测试,然后以并行方式打印它们…因为您要测试两个不同的条件,并且一次只能有一个是真的。你知道吗
概念证明
输出
相关问题 更多 >
编程相关推荐