zoukankan      html  css  js  c++  java
  • 平时不会的题

    列表的增加

    l=[1,2,'d']
    l[1]=['a',9,'p']
    print(l)
    #[1, ['a', 9, 'p'], 'd']
    l[1:2]=['a',9,'p']
    print(l)
    #[1, 'a', 9, 'p', 'd']
    购物车:
    goods = [{"name": "电脑", "price": 1999},
             {"name": "鼠标", "price": 10},
             {"name": "游艇", "price": 20},
             {"name": "美女", "price": 998},]
    shopping_car = []
    flag = True
    while flag:
        asset_total = input('请输入你的总资产:')
        if asset_total.isdigit():
            asset_total = int(asset_total)
            print('*****请选择以下商品*****')
            for index,i in enumerate(goods,1):
                print('	{0}	{1}	{2}'.format(index, i['name'], i['price']))
            print('************************')
            while True:
                goods_num = input('请选择您输入的商品序号(输入Q或者q为退出):')
                if goods_num.isdigit():
                    goods_num = int(goods_num)
                    if goods_num > 0 and goods_num <= len(goods):
                        goods_price = goods[goods_num - 1]['price']
                        if asset_total >= goods_price:
                            asset_total = asset_total - goods_price
                            shopping_car.append(goods[goods_num - 1])
                            print('您已经成功购买%s,您的余额是%d' %(goods[goods_num - 1]['name'],asset_total))
                        else:print('您的余额不足')
                    else:print('请输入正确的数字')
                elif goods_num.lower() == 'q':
                    print('您已经购买了如下商品')
                    for i in shopping_car:
                        print(i)
                    print('您的余额为%s' %asset_total)
                    flag = False
                    break
                else:print("请输入数字")
        else:print('请输入正确的数字')

     三级菜单:

    menu = {
        '北京': {
            '海淀': {
                '五道口': {
                    'soho': {},
                    '网易': {},
                    'google': {}
                },
                '中关村': {
                    '爱奇艺': {},
                    '汽车之家': {},
                    'youku': {},
                },
                '上地': {
                    '百度': {},
                },
            },
            '昌平': {
                '沙河': {
                    '老男孩': {},
                    '北航': {},
                },
                '天通苑': {},
                '回龙观': {},
            },
            '朝阳': {},
            '东城': {},
        },
        '上海': {
            '闵行': {
                "人民广场": {
                    '炸鸡店': {}
                }
            },
            '闸北': {
                '火车战': {
                    '携程': {}
                }
            },
            '浦东': {},
        },
        '山东': {},
    }
    def menu_3(menu):
        while True:
            for key in menu:
                print(key)
            choice=input('选择:')
            if choice == 'q' or choice == 'b':
                return choice
            elif choice in menu and menu_3(menu[choice]):
                borq = menu_3(menu[choice])
                if borq == 'q':
                    return 'q'
    menu_3(menu)
  • 相关阅读:
    nginx加php(三) 启动脚本
    nginx加php(一)
    xshell设置
    SQL的DDL和DML
    Python操作MongoDB
    OpsManager管理MongoDB
    MongoDB-GridFS
    执行计划及慢查询
    监控指标
    备份恢复
  • 原文地址:https://www.cnblogs.com/hzhcdhm/p/7727038.html
Copyright © 2011-2022 走看看