zoukankan      html  css  js  c++  java
  • 作业一:购物车程序

      1 # 1.三级菜单
      2 menu = {
      3     '北京':{
      4         '海淀':{
      5             '五道口':{
      6                 'soho':{},
      7                 '网易':{},
      8                 'google':{}
      9             },
     10             '中关村':{
     11                 '爱奇艺':{},
     12                 '汽车之家':{},
     13                 'youku':{},
     14             },
     15             '上地':{
     16                 '百度':{},
     17             },
     18         },
     19         '昌平':{
     20             '沙河':{
     21                 '老男孩':{},
     22                 '北航':{},
     23             },
     24             '天通苑':{},
     25             '回龙观':{},
     26         },
     27         '朝阳':{},
     28         '东城':{},
     29     },
     30     '上海':{
     31         '闵行':{
     32             "人民广场":{
     33                 '炸鸡店':{}
     34             }
     35         },
     36         '闸北':{
     37             '火车战':{
     38                 '携程':{}
     39             }
     40         },
     41         '浦东':{},
     42     },
     43     '山东':{},
     44 }
     45 
     46 exit_tag=True
     47 while exit_tag:
     48     for key in menu:
     49         print(key)
     50     choice=input('>: ').strip()
     51     if choice == 'quit':
     52         exit_tag=False
     53         continue
     54     if len(choice) == 0:
     55         continue
     56 
     57     if choice in menu:
     58         while exit_tag:
     59             first= menu[choice]
     60             for key2 in second: #第二层循环
     61                 print(key2)
     62             choice2=input('>>:').strip()
     63             if choice2 == 'bye':
     64                 break
     65             if choice2 == 'quit':
     66                 exit_tag = False
     67                 continue
     68             if len(choice2) == 0:
     69                 continue
     70             if choice2 in first:
     71                 while exit_tag:
     72                     second = first[choice2]
     73                     for key3 in second: #第三层
     74                         print(key3)
     75                     choice3 = input('>>>: ').strip()
     76                     if choice3 == 'bye':
     77                         break
     78                     if choice3 == 'quit':
     79                         exit_tag = False
     80                         continue
     81                     if  choice3 in third:
     82                         third = second[choice3]
     83                         for key4 in third:
     84                             print(key4)
     85                         choice4 = input('>>>>: ').strip()
     86                         if  choice4 == 'bye':
     87                             break
     88                         if choice4 == 'quit':
     89                             exit_tag=False
     90                             continue
     91 #
     92 # 2.购物车程序:
     93 good = {
     94     '1':{'apple': 100},
     95     '2':{'tesla': 100},
     96     '3':{'mac': 100},
     97     '4':{'lenovo': 100},
     98     '5':{'chicken': 100},
     99 }
    100 shoping_list = []
    101 exit_tag = True
    102 count = 0
    103 while exit_tag:
    104     account = input('your acconut: ').strip('|')
    105     password = input('your password: ').strip()
    106     with open('login.txt', 'r') as file:
    107         pair = file.read().split('|')
    108         name, secert = pair
    109         # print(name,secert)
    110     if account not in pair:
    111         print('用户名不存在')
    112     if account == name and password == secert:
    113         print('登陆成功')
    114         salary = input('请输入你的工资: ').strip()
    115         if salary == 'quit':
    116             exit_tag = False
    117             continue
    118         if not salary.isdigit():
    119             print('请重新输入(工资必须为数字):')
    120         else:
    121             salary_balance = int(salary)
    122             while exit_tag:
    123                 for key in good:
    124                     print(key,good[key])
    125                 serial = input('请输入商品编号: ').strip()
    126                 if serial == 'quit':
    127                     exit_tag = False
    128                     continue
    129                 if serial in good:
    130                     number = input('请输入购买的商品个数:').strip()
    131                     if  number.isdigit():
    132                         goods_name = list(good[serial])[0]
    133                         goods_price = good[serial][goods_name]
    134                         print('你选择购买的商品为:%s  单价为:%s  购买个数为: %s' %(goods_name,goods_price,number))
    135                         shoping_list.append((goods_name,goods_price,number))
    136                         goods_sum = int(goods_price)*int(number)
    137                         salary_balance -= goods_sum
    138                         if salary_balance < 0:
    139                             print('你的账户余额不足,退出!')
    140                             exit_tag = False
    141                             continue
    142                         else:
    143                             continue
    144                     else:
    145                         print('商品个数必须为数字:')
    146                 else:
    147                     print('请输入正确的商品编号: ')
    148             print('你的购物清单为%s \n' %(shoping_list))
    149     else:
    150         print('你输入的密码不对,请重新输入!')
    151         count += 1
    152     if count > 2:
    153         print('你尝试的次数过多,请稍后再试!')
    154         exit_tag =False
    155         continue
  • 相关阅读:
    activiti app 6.0 乱码
    扫盲--CRM系统和ERP系统的区别
    GraphQL实战-第四篇-构建开发框架
    GraphQL实战-第三篇-spring Boot 实现
    GraphQL实战-第二篇-java实现及分析
    GraphQL实战-第一篇-GraphQL介绍
    @PostConstruct及跳坑记录
    jmeter元件的介绍
    Docker之5. 容器的操作
    Docker之4. 镜像的操作
  • 原文地址:https://www.cnblogs.com/lincappu/p/8143867.html
Copyright © 2011-2022 走看看