商品仓库管理系统
1.出库 2.入库 3.增加商品 4.删除商品 5.修改商品 6.展示所有商品
不多说直接上代码:
def Displaymenu():
print("-"*35)
print("{: >18}".format("仓库管理系统"))
print("{: >18}".format("1.商品入库"))
print("{: >18}".format("2.商品出库"))
print("{: >20}".format("3.增加商品信息"))
print("{: >20}".format("4.删除商品信息"))
print("{: >20}".format("5.修改商品信息"))
print("{: >20}".format("6.查看商品信息"))
print("{: >18}".format("0.退出系统"))
print("-"*35)
goods_information=[]
def add_goods_information():
while True:
new_num = input('请输入商品的编号:')
new_name = input('请输入商品的名字:')
new_amount = input('请输入商品的数量:')
new_cost = input('请输入商品的进价:')
new_price = input('请输入商品的售价:')
new_goods = {}
new_goods['num']=new_num
new_goods['name']=new_name
new_goods['amount']=new_amount
new_goods['cost']=new_cost
new_goods['price']=new_price
goods_information.append(new_goods)
a = input('是否继续增加商品?(输入1继续,输入0结束)')
if a == '1':
continue
else:
print('保存成功!')
show_goods_information()
break
def find_goods_information(find_num):
find_goods=-1
for a in goods_information:
if a['num'] == find_num:
find_goods=goods_information.index(a)
return find_goods
def del_goods_information():
del_num = input("请输入要删除的商品编号:")
goods_addresss = find_goods_information(del_num)
if goods_addresss == -1:
print('商品不存在!')
else:
del goods_information[goods_addresss]
print('删除成功!')
show_goods_information()
def modify_goods_information():
modify_num = input("请输入要修改的商品编号:")
goods_address = find_goods_information(modify_num)
if goods_address == -1:
print('商品不存在!')
else:
new_name = input("请输入新的名字:")
new_cost = input("请输入新的进价")
new_price = input("请输入新的售价")
goods_information[goods_address]['name'] = new_name
goods_information[goods_address]['cost'] = new_cost
goods_information[goods_address]['price'] = new_price
print('修改成功!')
show_goods_information()
def show_goods_information():
print("-"*30)
print("{: >15}".format("商品总览"))
print("-"*30)
print("{: >20}".format("编号 名字 数量 进价 售价"))
for a in goods_information:
print("{: >20}".format("%s %s %s %s %s")%(a['num'],a['name'],a['amount'],a['cost'],a['price']))
def out():
while True:
out_num = input('请输入需要出库的商品编号:')
goods_address = find_goods_information(out_num)
if goods_address == -1:
print('商品不存在!')
continue
else:
a = eval(input('请输入出库数量:'))
print()
if int(goods_information[goods_address]['amount']) >= a:
b = int(goods_information[goods_address]['amount'])
goods_information[goods_address]['amount'] = b-a
else:
print('商品仓库数量不足!')
def storage():
while True:
ru_num = input('请输入需要出库的商品编号:')
goods_address = find_goods_information(ru_num)
if goods_address == -1:
print('商品不存在!')
continue
else:
a = eval(input('请输入出库数量:'))
print()
b = int(goods_information[goods_address]['amount'])
goods_information[goods_address]['amount'] = b + a
def main():
while True:
Displaymenu()
a = input('请输入功能对应的数字:')
if a == '1':
storage()
elif a == '2':
out()
elif a == '3':
add_goods_information()
elif a == '4':
del_goods_information()
elif a == '5':
modify_goods_information()
elif a == '6':
show_goods_information()
elif a == '0':
quit_confirm = input('输入end确定退出程序')
if quit_confirm == 'end':
break
else:
print('输入有误,请重新输入:')
if __name__ == '__main__':
main()
用到的函数很少,不知道作用的,自行搜索,抄作业很简单,理解最重要
|