Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python to realize supermarket purchase, Sale and Storage Management system

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to use python to realize the supermarket purchase, sale and storage management system". In the operation of the actual case, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Object-oriented programming

Realization of supermarket purchase, Sale and Storage Management system based on python

The system includes 7 kinds of operations, which are: 1. Inquire about all goods; 2. Add goods; 3. Modify the commodity; 4. Delete goods; 5. Sell goods; 6. Summary; 0. Exit the system.

Define a commodity class

# define a commodity class class Goods: def _ init__ (self,name,num,cin,cout): self.name = name self.num = num self.cin = cin self.cout = cout def _ str__ (self): state = "sold out" if self.num = = 0: return 'name:% s, quantity:% d% s Purchase price:% .2f, sale price:% .2f'% (self.name,self.num,state,self.cin,self.cout) else: return 'name:% s, quantity:% d, purchase price:% .2f, sale price:% .2f'% (self.name,self.num,self.cin Self.cout) defines a summary class # defines a summary class class gGoods: def _ init__ (self,name,gnum,gcin,gcout): self.name = name self.gnum = gnum self.gcin = gcin self.gcout = gcout def _ _ str__ (self): return 'name:% s, sold quantity:% d, purchase price:% .2f Selling price:% .2f'% (self.name,self.gnum,self.gcin,self.gcout)

Define managed commodity category

# define the management commodity class class GoodsManager: go= [] js= [] # Construction method def init (self): self.go.append (Goods ('Milk', 5 magi 40 ~ (60) self.go.append (Goods ('box lunch', 5 ~ 10 ~ 10 ~ (60)) self.js.append (gGoods ('Mushroom Niang') ) # menu def Menu (self): self.init () print ('\ "supermarket inventory management system\" menu:') print ("1. Show all goods ") print (" 2. Add new goods ") print (" 3. Modify commodity information ") print (" 4. Delete goods ") print (" 5. Sell goods ") print (" 6. Summary ") print (" 0. Exit ") print (" * * ") while True: SN=int (input (" = Please enter the operation number: ")) if SN in [0Jing 1Jing 2Jing 3Jing 4JI 5 6]: if SN = = 0: print ("exited") break If SN = = 1: self.Show_all () elif SN = 2: self.Add () elif SN = = 3: self.Modify () elif SN = = 4: self.Delete () Elif SN = = 5: self.Shop () elif SN = = 6: self.Summary () else: print ("incorrect input!") # display def Show_all (self): for goods in self.go: print (str (goods)) # add def Add (self): goods_name = input ("Please enter commodity name:") ret = self.check (goods_name) if ret! = None: print ('commodity already exists') print ('whether or not to increase the quantity of goods: (YPao)') while True: pd = input () if pd = = 'yboy: goods_num = int (input ("please enter the quantity of goods:") old_goods = Goods (goods_name) Goods_num+ret.num,ret.cin Ret.cout) self.go.remove (ret) self.go.append (old_goods) print ("added successfully") break elif pd = 'nsuccessful: print ("returned") break Else: print ("incorrect input Re-enter: ") else: goods_num = int (input (" Please enter the quantity of goods: ") goods_cin = float (input (" Please enter the purchase price: ")) goods_cout = float (input (" please enter the shipping price: ") if goods_num > 0 and goods_cin > 0 and goods_ Cout > 0: new_goods= Goods (goods_name Goods_num,goods_cin,goods_cout) self.go.append (new_goods) print ("add successfully") else: print ("cutie" Input error! ") # modify def Modify (self): goods_name = input ("Please enter the name of the product to be modified:") ret = self.check (goods_name) if ret! = None: print (ret) goods_name1 = input ("Please enter the name of the modified product:") goods_num = int ("Please enter the modified quotient Quantity of goods: ") goods_cin = float (input (" Please enter the purchase price of the modified goods: ") goods_cout = float (input (" please enter the shipping price of the modified goods: ") old_goods= Goods (goods_name1) Goods_num,goods_cin,goods_cout) self.go.remove (ret) self.go.append (old_goods) print ("modified successfully") else: print ("cutie" There is no such product!) # check def check (self,goods_name): for goods in self.go: if goods.name = = goods_name: return goods else: return None # check js def checkjs (self Goods_name): for goods in self.js: if goods.name = = goods_name: return goods else: return None # Delete def Delete (self): goods_name = input ("Please enter the trade name to be deleted:") ret = self.check (goods_name) if ret! = None: Print (ret) print ('whether or not to delete goods: (YSEO)') while True: pd = input () if pd = = 'yellows: self.go.remove (ret) print ("deleted successfully") break Elif pd ='n error: print ("returned") break else: print ("incorrect input") Re-enter: ") else: print (" cutie, we don't have this product! ") # sell def Shop (self): goods_name = input ("Please enter the name of the product to be sold:") ret = self.check (goods_name) if ret! = None: g_num=int ("number sold:") if ret.num-g_num

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report