python 3.x - How do I get the programme to print out the receipt format with the correct subtotal? -


thanks help. want print out orders in format:

85791008     mango-1           £1     3    £3 86139113    strawberries-500g  £1.50  2    £3 total cost of order:                       £6 

this code:

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 gtin-8 code of product purchase: ')     row in purchase:         field in row:             if order in field:                 quantity=int(input('how of 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 add iem order, yes or no: ')                 if option=='no':                     user_order in user_orders:                         print('\n' + user_order)                     print('\ntotal cost of order:                                                 '+ "{:10.2f}".format(final_price)) 

how edit print out in format @ top?

the main problem code you've declared default vars inside loop , reset on every iteration (final_price, user_orders). apart this, formatting messed , you've used int type prices, not idea. there error when price in csv file has floating point.

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 gtin-8 code of product purchase: ')     row in purchase:         field in row:             if order in field:                 quantity=int(input('how of 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 add iem order, yes or no: ')                 if option=='no':                     user_order in user_orders:                         print('\n' + user_order)                     print('\ntotal cost of order:                                                 '+ "{:10.2f}".format(final_price)) 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -