gpt4 book ai didi

python - 如何 'rearrange' 我的 python 代码适合某种格式?

转载 作者:太空宇宙 更新时间:2023-11-03 16:41:29 26 4
gpt4 key购买 nike

这是我目前的代码。请注意“percentageOff”和“originalPrices”是其中包含 float /整数的列表。

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

x = [1,2,3,4,5,34]
y = [3,4,5,6,5,4]
print("Percent off:",end="\t")

for i, j in zip(x, y):
print(i, '\t\t', j,end="\n\t\t")

输出是;

Percent off:    1        3
2 4
3 5
4 6
5 5
34 4

关于python - 如何 'rearrange' 我的 python 代码适合某种格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36741505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com