ご協力いただきありがとうございます。私は、この形式で注文をプリントアウトしたい:正しい小計で領収書書式を印刷するプログラムを取得するにはどうすればよいですか?
85791008 Mango-1 £1 3 £3
86139113 Strawberries-500g £1.50 2 £3
Total cost of order: £6
これは私のコードです:
import csv
option='yes'
user_orders=[]
final_price=0.00
while option=='yes':
data=open('Product information.csv', 'rt')
purchase=csv.reader(data)
order=input('Please enter the GTIN-8 code of the product you would like to purchase: ')
for row in purchase:
for field in row:
if order in field:
quantity=int(input('How much of that item: '))
final_price=quantity*float(row[2]) + final_price
receipt=('{} {} {} {} {}'.format(row[0]+' ', row[1]+' ', str(quantity)+' ', "{:10.2f}".format(float(row[2]))+' ', "{:10.2f}".format(quantity * float(row[2]))))
user_orders.append(receipt)
print('You have added '+(receipt))
option=input('Would you like to add another iem to your order, yes or no: ')
if option=='no':
for user_order in user_orders:
print('\n' + user_order)
print('\nTotal cost of order: '+ "{:10.2f}".format(final_price))
はどのようにして上部の形式でプリントアウトするために、これを編集するには?
私の答えに表示されているように、最後の印刷ステートメントをループから移動します。 –