标签:移除 style 简单实现 open none 信息 型号 vivo 选项
2017-12-09
手机品牌 手机价格 库存数量
vivoX9 2798 25
iphone7(32G) 4888 31
iphone7(128G) 5668 22
iphone7P(128G) 6616 29
iphone6(16G) 3858 14
....
....
...
功能要求:
四个选项:
vivoX9 2798 25
iphone7(32G) 4888 31
iphone7(128G) 5668 22
iphone7P(128G) 6616 29
iphone6(16G) 3858 14
.................
..................
分支选项:
1.选择产品序号查看详情(根据序号输出产品名称,价格,库存)
1.购买(库存数量-1,库存为0时,删除该产品)
2.返回
2.返回
1.添加新产品(添加新产品,包括产品名称、价格、库存)
2.修改原有产品
输出所有产品信息
1.根据选择序号进行修改
2.返回
1.查看所有产品,根据序号移除
2.移除所有产品
3.返回
代码如下:
首先定义第一个歩骤的函数.
1 def cha_kan(): 2 if len(all_phone): 3 for x in xrange(0,len(all_phone)): 4 phone = all_phone[x] 5 result =phone.values() 6 print x+1,‘.‘, result[2] 7 print ‘‘‘ 8 1.选择产品序号查看详情 9 2.返回‘‘‘ 10 cao_zuo = input(‘请输入操作序号: \n‘) 11 while cao_zuo != 1 and cao_zuo != 2: 12 cao_zuo = input(‘序号错误!!请重新输入操作序号: n‘) 13 if cao_zuo ==1: 14 num = input(‘请输入手机序号: ‘) 15 while num <0 or num >len(all_phone): 16 num = input(‘手机不存在请重新输入手机序号: ‘) 17 if num ==1: 18 one = all_phone[0] 19 print ‘型号为: ‘,one[‘name‘] 20 print ‘价格为: ‘,one[‘price‘] 21 print ‘库存为: ‘,one[‘count‘] 22 elif num==2: 23 one = all_phone[1] 24 print ‘型号为: ‘,one[‘name‘] 25 print ‘价格为: ‘,one[‘price‘] 26 print ‘库存为: ‘,one[‘count‘] 27 elif num==3: 28 one = all_phone[2] 29 print ‘型号为: ‘,one[‘name‘] 30 print ‘价格为: ‘,one[‘price‘] 31 print ‘库存为: ‘,one[‘count‘] 32 elif num==4: 33 one = all_phone[3] 34 print ‘型号为: ‘,one[‘name‘] 35 print ‘价格为: ‘,one[‘price‘] 36 print ‘库存为: ‘,one[‘count‘] 37 elif num==5: 38 one = all_phone[4] 39 print ‘型号为: ‘,one[‘name‘] 40 print ‘价格为: ‘,one[‘price‘] 41 print ‘库存为: ‘,one[‘count‘] 42 gou_mai() 43 else: 44 pass 45 else: 46 print ‘so sorry!!!暂时没有产品!!‘
依次是第二第三歩骤的函数:
1 def cha_kan(): 2 if len(all_phone): 3 for x in xrange(0,len(all_phone)): 4 phone = all_phone[x] 5 result =phone.values() 6 print x+1,‘.‘, result[2] 7 print ‘‘‘ 8 1.选择产品序号查看详情 9 2.返回‘‘‘ 10 cao_zuo = input(‘请输入操作序号: \n‘) 11 while cao_zuo != 1 and cao_zuo != 2: 12 cao_zuo = input(‘序号错误!!请重新输入操作序号: n‘) 13 if cao_zuo ==1: 14 num = input(‘请输入手机序号: ‘) 15 while num <0 or num >len(all_phone): 16 num = input(‘手机不存在请重新输入手机序号: ‘) 17 if num ==1: 18 one = all_phone[0] 19 print ‘型号为: ‘,one[‘name‘] 20 print ‘价格为: ‘,one[‘price‘] 21 print ‘库存为: ‘,one[‘count‘] 22 elif num==2: 23 one = all_phone[1] 24 print ‘型号为: ‘,one[‘name‘] 25 print ‘价格为: ‘,one[‘price‘] 26 print ‘库存为: ‘,one[‘count‘] 27 elif num==3: 28 one = all_phone[2] 29 print ‘型号为: ‘,one[‘name‘] 30 print ‘价格为: ‘,one[‘price‘] 31 print ‘库存为: ‘,one[‘count‘] 32 elif num==4: 33 one = all_phone[3] 34 print ‘型号为: ‘,one[‘name‘] 35 print ‘价格为: ‘,one[‘price‘] 36 print ‘库存为: ‘,one[‘count‘] 37 elif num==5: 38 one = all_phone[4] 39 print ‘型号为: ‘,one[‘name‘] 40 print ‘价格为: ‘,one[‘price‘] 41 print ‘库存为: ‘,one[‘count‘] 42 gou_mai() 43 else: 44 pass 45 else: 46 print ‘so sorry!!!暂时没有产品!!‘
1 def yi_chu(): 2 print ‘‘‘ 3 1.查看所有产品,根据序号移除 4 2.移除所有产品 5 3.返回‘‘‘ 6 xh = input(‘请输入序号: ‘) 7 while xh != 1 and xh !=2 and xh !=3: 8 xh = input(‘序号错误:!!!重新输入序号: ‘) 9 if xh==1: 10 for x in xrange(0,len(all_phone)): 11 phone = all_phone[x] 12 result =phone.values() 13 print x+1,‘.‘, result[2] 14 gen_ju = input(‘根据序号删除,请输入序号: ‘) 15 while gen_ju <0 or gen_ju >len(all_phone): 16 gen_ju = input(‘序号错误:!!!重新输入序号: ‘) 17 if gen_ju ==1: 18 all_phone.pop(gen_ju-1) 19 print ‘删除成功!!‘ 20 elif gen_ju ==2: 21 all_phone.pop(gen_ju-1) 22 print ‘删除成功!!‘ 23 elif gen_ju ==3: 24 all_phone.pop(gen_ju-1) 25 print ‘删除成功!!‘ 26 elif gen_ju ==4: 27 all_phone.pop(gen_ju-1) 28 print ‘删除成功!!‘ 29 elif gen_ju ==5: 30 all_phone.pop(gen_ju-1) 31 print ‘删除成功!!‘ 32 elif xh ==2: 33 while len(all_phone): 34 del all_phone[0] 35 print ‘删除成功!!‘ 36 else: 37 pass
又额外写了一个查看内部购买的函数
1 def gou_mai(): 2 print ‘‘‘ 3 1-购买 4 2-返回‘‘‘ 5 xz = input(‘请输入操作序号: ‘) 6 while xz != 1 and xz != 2: 7 xz = input(‘输入错误!!请重新输入操作序号: ‘) 8 if xz == 1: 9 one = all_phone[0] 10 value= int(one[‘count‘])-1 11 one[‘count‘] = str(value) 12 print ‘购买成功!!!‘ 13 else: 14 pass
然后开始写整个主体的歩骤
1 while 1: 2 print ‘‘‘ 3 1.查看所有手机品牌 4 2.更改产品库存信息 5 3.移除产品库存信息 6 4.退出程序‘‘‘ 7 shu_ru = input(‘请输入操作序号: ‘) 8 while shu_ru != 1 and shu_ru != 2 and shu_ru != 3 and shu_ru != 4 : 9 shu_ru = input(‘输入错误!!!请重新输入操作序号: ‘) 10 if shu_ru ==1: 11 cha_kan() 12 elif shu_ru == 2: 13 geng_gai() 14 elif shu_ru == 3: 15 yi_chu() 16 else: 17 break
里面还有很多的错误.基本能够运行,以后学会了其他的方法再进来更改.
标签:移除 style 简单实现 open none 信息 型号 vivo 选项
原文地址:http://www.cnblogs.com/Chai-zz/p/8011451.html