Python超市进销存管理系统!老妈开超市有系统了

开发 后端
python实现超市进销存管理系统,系统包括7种操作,分别是:1.查询所有商品;2.添加商品;3.修改商品;4.删除商品;5.卖出商品;6.汇总;0.退出系统。

面向对象程序设计

python实现超市进销存管理系统

系统包括7种操作,分别是:1.查询所有商品;2.添加商品;3.修改商品;4.删除商品;5.卖出商品;6.汇总;0.退出系统。

定义一个商品类

 

  1. #定义一个商品类 
  2. class Goods: 
  3.     def __init__(self,name,num,cin,cout): 
  4.         self.name = name 
  5.         self.num = num 
  6.         self.cin  = cin 
  7.         self.cout = cout 
  8.     def __str__(self): 
  9.         state = "已售罄" 
  10.         if self.num == 0: 
  11.             return '名称:%s , 数量:%d %s, 进货价格:%.2f ,售出价格:%.2f '%(self.name,self.num,state,self.cin,self.cout) 
  12.         else
  13.             return '名称:%s , 数量:%d , 进货价格:%.2f ,售出价格:%.2f '%(self.name,self.num,self.cin,self.cout) 
  14.  
  15. 定义一个汇总类 
  16.  
  17. #定义一个汇总类 
  18. class gGoods: 
  19.     def __init__(self,name,gnum,gcin,gcout): 
  20.         self.name = name 
  21.         self.gnum = gnum 
  22.         self.gcin = gcin 
  23.         self.gcout = gcout 
  24.     def __str__(self): 
  25.         return '名称:%s , 卖出数量:%d , 进货价格:%.2f ,卖出价格:%.2f '%(self.name,self.gnum,self.gcin,self.gcout) 

定义管理商品类

 

  1. #定义管理商品类 
  2. class GoodsManager: 
  3.     go=[] 
  4.     js=[] 
  5.     #构造方法 
  6.     def init(self): 
  7.         self.go.append(Goods('牛奶',5,40,60)) 
  8.         self.go.append(Goods('盒饭',5,10,60)) 
  9.         self.js.append(gGoods('菇娘',1,30,60)) 
  10.  
  11.     #菜单 
  12.     def Menu(self): 
  13.         self.init() 
  14.         print('\"超市进销存管理系统\"菜单:'
  15.         print("1.显示所有商品"
  16.         print("2.添加新的商品"
  17.         print("3.修改商品信息"
  18.         print("4.删除商品"
  19.         print("5.卖出商品"
  20.         print("6.汇总"
  21.         print("0.退出"
  22.         print("***********************************"
  23.         while True
  24.              
  25.             SN=int(input("===请输入操作序号:"))             
  26.             if SN in [0,1,2,3,4,5,6]: 
  27.                 if SN == 0: 
  28.                     print("已经退出"
  29.                     break; 
  30.                 if SN == 1: 
  31.                     self.Show_all() 
  32.                 elif SN  == 2: 
  33.                     self.Add() 
  34.                 elif SN == 3: 
  35.                     self.Modify() 
  36.                 elif SN == 4: 
  37.                     self.Delete() 
  38.                 elif SN == 5: 
  39.                     self.Shop() 
  40.                 elif SN == 6: 
  41.                     self.Summary() 
  42.  
  43.             else
  44.                 print("输入有误!"
  45.     #显示 
  46.     def Show_all(self): 
  47.         for goods in self.go: 
  48.             print (str(goods)) 
  49.     #添加 
  50.     def Add(self): 
  51.         goods_name = input("请输入商品名称:"
  52.         ret = self.check(goods_name) 
  53.         if ret != None: 
  54.             print('商品已经存在'
  55.             print('是否增加商品数量:(y/n)'
  56.             while True
  57.                 pd = input() 
  58.                 if pd == 'y'
  59.                     goods_num = int(input("请输入商品的数量:")) 
  60.                     old_goods = Goods(goods_name,goods_num+ret.num,ret.cin,ret.cout) 
  61.                     self.go.remove(ret) 
  62.                     self.go.append(old_goods) 
  63.                     print("增加成功"
  64.                     break 
  65.                 elif pd == 'n'
  66.                     print("已经返回"
  67.                     break 
  68.                 else
  69.                     print("输入有误,重新输入:"
  70.              
  71.         else
  72.             goods_num = int(input("请输入商品的数量:")) 
  73.             goods_cin = float(input("请输入商品进货价格:")) 
  74.             goods_cout = float(input("请输入商品出货价格:")) 
  75.             if goods_num>0 and goods_cin>0 and goods_cout>0: 
  76.                 new_goods= Goods(goods_name,goods_num,goods_cin,goods_cout) 
  77.                 self.go.append(new_goods) 
  78.                 print("添加成功"
  79.             else
  80.                 print("小可爱,输入错误!"
  81.     #修改 
  82.     def Modify(self): 
  83.         goods_name = input("请输入需要修改的商品名称:"
  84.         ret = self.check(goods_name) 
  85.         if ret != None: 
  86.             print(ret) 
  87.             goods_name1 = input("请输入修改后商品的名称:"
  88.             goods_num = int(input("请输入修改后商品的数量:")) 
  89.             goods_cin = float(input("请输入修改后商品进货价格:")) 
  90.             goods_cout = float(input("请输入修改后商品出货价格:")) 
  91.             old_goods= Goods(goods_name1,goods_num,goods_cin,goods_cout) 
  92.             self.go.remove(ret) 
  93.             self.go.append(old_goods)     
  94.             print("修改成功"
  95.         else
  96.             print("小可爱,没有此商品!"
  97.     #检查 
  98.     def check(self,goods_name): 
  99.         for goods in self.go: 
  100.             if goods.name == goods_name: 
  101.                 return goods 
  102.         else
  103.             return None 
  104.     #检查js 
  105.     def checkjs(self,goods_name): 
  106.         for goods in self.js: 
  107.             if goods.name ==goods_name: 
  108.                 return goods 
  109.         else
  110.             return None 
  111.     #删除 
  112.     def Delete(self): 
  113.         goods_name = input("请输入需要删除的商品名称:"
  114.         ret = self.check(goods_name) 
  115.         if ret != None: 
  116.             print(ret) 
  117.             print('是否删除商品:(y/n)'
  118.             while True
  119.                 pd = input() 
  120.                 if pd == 'y'
  121.                     self.go.remove(ret) 
  122.                     print("删除成功"
  123.                     break 
  124.                 elif pd == 'n'
  125.                     print("已经返回"
  126.                     break 
  127.                 else
  128.                     print("输入有误,重新输入:"
  129.         else
  130.             print("小可爱,没有此商品!"
  131.     #卖出 
  132.     def Shop(self): 
  133.         goods_name = input("请输入需要卖出的商品名称:"
  134.         ret = self.check(goods_name) 
  135.         if ret != None: 
  136.             g_num=int(input("卖出个数:")) 
  137.             if ret.num-g_num<0: 
  138.                 print("该商品数量不足!请补充"
  139.             else
  140.                 old_goods= Goods(ret.name,ret.num-g_num,ret.cin,ret.cout) 
  141.                 self.go.remove(ret) 
  142.                 self.go.append(old_goods) 
  143.                 gret = self.checkjs(goods_name) 
  144.                 if gret == None: 
  145.                     shop_goods = gGoods(ret.name,g_num,ret.cin*g_num,ret.cout*g_num) 
  146.                     self.js.append(shop_goods) 
  147.                 else
  148.                     shop_goods = gGoods(gret.name,g_num+gret.gnum,gret.gcin+ret.cin*g_num,gret.gcout+ret.cout*g_num) 
  149.                     self.js.remove(gret) 
  150.                     self.js.append(shop_goods) 
  151.                 print("卖出后:",end=' '
  152.                 old_goods= Goods(ret.name,ret.num-g_num,ret.cin*g_num,ret.cout*g_num) 
  153.                 print(old_goods) 
  154.                  
  155.         else
  156.             print("小可爱,没有此商品!"
  157.     #汇总当天卖出商品,包括每种销售商品名称、数量、进货总价、销售总价等。 
  158.     def Summary(self): 
  159.         for goods in self.js: 
  160.             print (str(goods)) 
  161.         print("售出的物品进货总价:",end=""
  162.         x=0 
  163.         for goods in self.js: 
  164.             x+=float(goods.gcin) 
  165.         print(x) 
  166.         print("售出的物品销售总价:",end=""
  167.         y=0 
  168.         for goods in self.js: 
  169.             y+=float(goods.gcout) 
  170.         print(y) 
  171.         print("利润:",y-x);``` 

 

[[351434]]

 

责任编辑:未丽燕 来源: 今日头条
相关推荐

2017-07-05 16:15:54

互联网

2021-12-08 16:21:11

网络攻击黑客网络安全

2023-06-05 11:33:43

商品销存编码

2024-05-10 12:01:00

商品分析数据分析断货

2022-11-29 11:31:19

商品分析商品销售库存

2011-01-14 10:24:31

2011-05-17 10:27:27

AvayaApp Store应用商店

2013-06-14 12:43:50

深信服应用交付AD

2021-07-08 15:51:26

Coop勒索软件攻击Kaseya

2010-05-28 10:48:49

云计算

2019-03-04 10:32:41

2017-08-21 09:54:31

承包 移动

2019-10-31 13:17:13

无人超市人脸识别移动支付

2012-01-04 16:39:45

2020-08-03 23:16:51

物联网冠状病毒IOT

2015-02-05 13:27:02

移动开发模块SDK

2012-07-12 14:09:20

侠诺网络传输VPN

2015-07-01 11:41:53

物联网超市转型

2013-08-09 09:18:25

阿里余额宝阿里云
点赞
收藏

51CTO技术栈公众号