anirudhp06

Grocery 1.2.5

May 2nd, 2020 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.64 KB | None | 0 0
  1. """Made Minor changes from grocery 1.2 - grocery 1.2.5
  2. from now the program outputs file which stores the items entered with proper bill....
  3. TL;DR Every time you use 'bill' option the program will save the items and rate in text file whose name is same of the present date and will be stored locally.... also the 'bill' function now will reset the items and rate after appending those information to the '.txt' file If u face any problems while using program do ping me... am on reddit u/anirudhp06 """
  4.  
  5.  
  6. import sys
  7. import datetime#Required For file generation
  8. class grocery:
  9.     today=datetime.date.today()#To fetch the date
  10.     file=open("{}.txt".format(today),"a+")#Will create a file with corresponding date
  11.     file.write("{} Loggigng of expenditure started\n\n".format(datetime.datetime.now()))#First Line of the file
  12.     a=[]#To store Name of Items
  13.     b=[]#To store rate of corresponding Items
  14.     bill=0
  15.     serial=0
  16.     choice=0#Use this in further Input
  17.     def order(self):
  18.         print("Name of Item:")
  19.         nome = input()
  20.         self.a.append(nome)#Append the item name to the list
  21.         print("Rate of Item:")
  22.         rate = int(input())
  23.         self.b.append(rate)#Append the rate of the same item to list
  24.  
  25.     def display(self):
  26.         series=0
  27.         if self.a == []:
  28.             print("Your Bucket List is empty! Insert Item")
  29.         else:
  30.             for i in range(0, len(self.a)):
  31.                 series+=1
  32.                 print("{}. {},{}/-".format(series,self.a[i], self.b[i]))
  33.  
  34.     def billl(self):
  35.         self.bill= 0 # Again Re-Initializing bill to 0
  36.         for i in self.b:
  37.             self.bill += i #adding up all the rate from List b
  38.         print("\t\tYour Bill is :", self.bill, "/-")
  39.         self.file.write("List of items and its rate:\n")
  40.         for i in range(len(self.a)):
  41.             self.file.write("{},{}/-\n".format(self.a[i],self.b[i]))#Writes Items and its rate
  42.         self.file.write("Total Bill:{}".format(self.bill))#Writes total bill in '.txt' file
  43.         self.file.write("\n\n")
  44.         self.a.clear()#Clears out the items from list
  45.         self.b.clear()#Clears out the rate of items from list
  46.        
  47.  
  48.     def remove(self):
  49.         if self.a == []:
  50.             print("Your Bucket List is empty! Insert Item")
  51.         else:
  52.             self.serial = int(input("Enter Serial Number of Item to remove:"))
  53.             if self.serial > len(self.a):
  54.                 print("Out of Range Try again")
  55.             else:
  56.                 self.serial=self.serial-1
  57.                 self.a.remove(self.a[self.serial])
  58.                 self.b.remove(self.b[self.serial])
  59.                 print("List Updated")
  60.  
  61.     def edit(self):
  62.         self.serial=int(input("Enter Serial Number of Item to edit:"))
  63.         if self.serial>len(self.a):
  64.             print("Out of Range Try again")
  65.         else:
  66.             self.serial=self.serial-1
  67.             print("What do u want to change? \n1.Name\n2.Rate\n3.Both")
  68.             bol=int(input())
  69.             if bol==1:
  70.                 self.a.remove(self.a[self.serial])
  71.                 new_nome=input("Enter New name for it:")
  72.                 self.a.insert(self.serial,new_nome)
  73.                 print("List Updated")
  74.  
  75.  
  76.             elif bol==2:
  77.                 self.b.remove(self.b[self.serial])
  78.                 new_rate = int(input("Enter New rate to it:"))
  79.                 self.b.insert(self.serial,new_rate)
  80.                 print("Rate Updated")
  81.  
  82.             elif bol==3:
  83.                 self.a.remove(self.a[self.serial])
  84.                 new_nome = input("Enter New name for it:")
  85.                 self.a.insert(self.serial, new_nome)
  86.                 print("Name Updated")
  87.                 self.b.remove(self.b[self.serial])
  88.                 new_rate=int(input("Enter New rate to it:"))
  89.                 self.b.insert(self.serial,new_rate)
  90.                 print("Rate Updated")
  91.  
  92.  
  93.     def input(self):
  94.         while self.choice!=6:
  95.             print("\n\n1.Insert Grocery\n2.Display Bucket List\n3.Total Bill\n4.Remove item\n5.Edit Item\n6.Exit")
  96.             self.choice=int(input("\nEnter Choice:"))
  97.             if self.choice==1:
  98.                 self.order() #Calling all the functions
  99.  
  100.             elif self.choice==2:
  101.                 self.display()
  102.  
  103.             elif self.choice==3:
  104.                 self.billl()
  105.  
  106.             elif self.choice==4:
  107.                 self.remove()
  108.  
  109.             elif self.choice==5:
  110.                 self.edit()
  111.  
  112.             elif self.choice==6:
  113.                 print("Program Terminated")
  114.                 self.file.close()
  115.                 sys.exit()
  116.             else:
  117.                 print("Try Again")
  118.  
  119. obj=grocery()
  120. obj.input()
Add Comment
Please, Sign In to add comment