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

发布时间:2021-10-25 10:36:50 作者:iii
来源:亿速云 阅读:627

本篇内容介绍了“怎么用python实现超市进销存管理系统”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

面向对象程序设计

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

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

定义一个商品类

#定义一个商品类 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 = "已售罄"         if self.num == 0:             return '名称:%s , 数量:%d %s, 进货价格:%.2f ,售出价格:%.2f '%(self.name,self.num,state,self.cin,self.cout)         else:             return '名称:%s , 数量:%d , 进货价格:%.2f ,售出价格:%.2f '%(self.name,self.num,self.cin,self.cout)  定义一个汇总类  #定义一个汇总类 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 '名称:%s , 卖出数量:%d , 进货价格:%.2f ,卖出价格:%.2f '%(self.name,self.gnum,self.gcin,self.gcout)

定义管理商品类

#定义管理商品类 class GoodsManager:     go=[]     js=[]     #构造方法     def init(self):         self.go.append(Goods('牛奶',5,40,60))         self.go.append(Goods('盒饭',5,10,60))         self.js.append(gGoods('菇娘',1,30,60))      #菜单     def Menu(self):         self.init()         print('\"超市进销存管理系统\"菜单:')         print("1.显示所有商品")         print("2.添加新的商品")         print("3.修改商品信息")         print("4.删除商品")         print("5.卖出商品")         print("6.汇总")         print("0.退出")         print("***********************************")         while True:                          SN=int(input("===请输入操作序号:"))                         if SN in [0,1,2,3,4,5,6]:                 if SN == 0:                     print("已经退出")                     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("输入有误!")     #显示     def Show_all(self):         for goods in self.go:             print (str(goods))     #添加     def Add(self):         goods_name = input("请输入商品名称:")         ret = self.check(goods_name)         if ret != None:             print('商品已经存在')             print('是否增加商品数量:(y/n)')             while True:                 pd = input()                 if pd == 'y':                     goods_num = int(input("请输入商品的数量:"))                     old_goods = Goods(goods_name,goods_num+ret.num,ret.cin,ret.cout)                     self.go.remove(ret)                     self.go.append(old_goods)                     print("增加成功")                     break                 elif pd == 'n':                     print("已经返回")                     break                 else:                     print("输入有误,重新输入:")                      else:             goods_num = int(input("请输入商品的数量:"))             goods_cin = float(input("请输入商品进货价格:"))             goods_cout = float(input("请输入商品出货价格:"))             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("添加成功")             else:                 print("小可爱,输入错误!")     #修改     def Modify(self):         goods_name = input("请输入需要修改的商品名称:")         ret = self.check(goods_name)         if ret != None:             print(ret)             goods_name1 = input("请输入修改后商品的名称:")             goods_num = int(input("请输入修改后商品的数量:"))             goods_cin = float(input("请输入修改后商品进货价格:"))             goods_cout = float(input("请输入修改后商品出货价格:"))             old_goods= Goods(goods_name1,goods_num,goods_cin,goods_cout)             self.go.remove(ret)             self.go.append(old_goods)                 print("修改成功")         else:             print("小可爱,没有此商品!")     #检查     def check(self,goods_name):         for goods in self.go:             if goods.name == goods_name:                 return goods         else:             return None     #检查js     def checkjs(self,goods_name):         for goods in self.js:             if goods.name ==goods_name:                 return goods         else:             return None     #删除     def Delete(self):         goods_name = input("请输入需要删除的商品名称:")         ret = self.check(goods_name)         if ret != None:             print(ret)             print('是否删除商品:(y/n)')             while True:                 pd = input()                 if pd == 'y':                     self.go.remove(ret)                     print("删除成功")                     break                 elif pd == 'n':                     print("已经返回")                     break                 else:                     print("输入有误,重新输入:")         else:             print("小可爱,没有此商品!")     #卖出     def Shop(self):         goods_name = input("请输入需要卖出的商品名称:")         ret = self.check(goods_name)         if ret != None:             g_num=int(input("卖出个数:"))             if ret.num-g_num<0:                 print("该商品数量不足!请补充")             else:                 old_goods= Goods(ret.name,ret.num-g_num,ret.cin,ret.cout)                 self.go.remove(ret)                 self.go.append(old_goods)                 gret = self.checkjs(goods_name)                 if gret == None:                     shop_goods = gGoods(ret.name,g_num,ret.cin*g_num,ret.cout*g_num)                     self.js.append(shop_goods)                 else:                     shop_goods = gGoods(gret.name,g_num+gret.gnum,gret.gcin+ret.cin*g_num,gret.gcout+ret.cout*g_num)                     self.js.remove(gret)                     self.js.append(shop_goods)                 print("卖出后:",end=' ')                 old_goods= Goods(ret.name,ret.num-g_num,ret.cin*g_num,ret.cout*g_num)                 print(old_goods)                          else:             print("小可爱,没有此商品!")     #汇总当天卖出商品,包括每种销售商品名称、数量、进货总价、销售总价等。     def Summary(self):         for goods in self.js:             print (str(goods))         print("售出的物品进货总价:",end="")         x=0         for goods in self.js:             x+=float(goods.gcin)         print(x)         print("售出的物品销售总价:",end="")         y=0         for goods in self.js:             y+=float(goods.gcout)         print(y)         print("利润:",y-x);```
怎么用python实现超市进销存管理系统

“怎么用python实现超市进销存管理系统”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. 无人超市和传统超市的这些区别 你都知道吗?
  2. python怎么实现超市管理系统

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python

上一篇:linux中为什么要性能优化

下一篇:Python爬虫经常会被封的原因是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》