Retail shop billing

# File handling 
# Retail shop billing 

import sys
import math

stock=None
order=None

try:
stock = open(sys.argv[1],"r")
# create dictionary
PriceList={}
for line in stock:
item,price = line.split()
PriceList[item]=int(price)
# print(PriceList)
billamt=0
for i in range(2,len(sys.argv)):
order = open(sys.argv[i],"r")
print("S.no\tItem\t\tRate\tQuantity\tAmount")
i=1
for line in order:
item,qty=line.split()
price = int(qty)*PriceList[item]
print(i,"\t",item.ljust(10),"\t",PriceList[item],"\t",int(qty),"\t\t",price)
billamt = billamt+price
                        i+=1
print("Total Amount =", billamt)
cgst = round(billamt*.09,2)
sgst = round(billamt*.09,2)
print("cgst =",cgst)
print("sgst =",sgst)
print("Net Amount =",math.floor(billamt+cgst+sgst))
print("**"*30)
except IOError as e:
print("File opening error : ", e)
except:
print("unknown error")
else:
print("\nThank you for shopping with us\n")
print("**"*30)

finally:
if(stock):
stock.close()
if(order):
order.close()
"""
Sample output:
input file: (3)

ShopPricelist.txt 
Walnut 700
Figs 520
Raisins 400
Chashewnut 680
Almond 700
Pistachio 1400
Dates 440
Apricot 650
Kiwi 680
Cardamon 3000
Pepper 480

custorder1.txt 
Walnut 1
Raisins 4
Almond 7
Dates 2

custorder2.txt
Apricot 2
Kiwi 4
Cardamon 5
Pepper 3



>python retailshopbilling.py ShopPricelist.txt custorder1.txt custorder2.txt

S.no    Item                Rate    Quantity        Amount
1        Walnut             700         1                   700
2        Raisins             400         4                   1600
3        Almond            700         7                   4900
4        Dates                440         2                   880

Total Amount = 8080
cgst = 727.2
sgst = 727.2
Net Amount = 9534
************************************************************

S.no    Item                Rate    Quantity        Amount
1        Apricot             650          2                   1300
2        Kiwi                  680         4                   2720
3        Cardamon        3000       5                   15000
4        Pepper              480         3                   1440

Total Amount = 20460
cgst = 1841.4
sgst = 1841.4
Net Amount = 24142
************************************************************

Thank you for shopping with us

************************************************************


"""

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu