Dies ist mein Code im Moment. Bitte beachten Sie, dass "prozentualAus" und "originalPreise" Listen mit Floats/Ints sind.Wie ordne ich meinen Python-Code so an, dass er in ein bestimmtes Format passt?
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)
Der Ausgang ist (mit dem Rest des Codes):
**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
Aber ich möchte, dass die Ausgabe sein
**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
Wie kann ich mein Problem beheben?
Druckprozentanteil in derselben Schleife wie die neue Preis – lib
put 'für Prozentsatz in percentageOff [1]: print ("\ t \ t \ t", Prozentsatz, "%")' innen 'if (0
oneman
Verwenden Sie ['prettytable'] (https://pypi.python.org/pypi/PrettyTable)? –