博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python基础-四天(day16)
阅读量:7227 次
发布时间:2019-06-29

本文共 3623 字,大约阅读时间需要 12 分钟。

 运算符   

 

product_list = [['phone', 5000],                ['book1', 100],                ['变形金刚模型', 500],                ['小鱼仔一箱', 50],                ['伊利牛奶', 100]                ]shopping_cart = {}#字义购物车为一个字典salary = int(input("input you salary: "))while True:    index = 0    for product in product_list:        print(index,product)        index +=1    choice = input("请输入要购买的商品编号>>>:").strip()    if choice.isdigit():        choice = int(choice)        if choice >= 0 and choice < len(product_list):            product = product_list[choice]            if product[1] <= salary:                if product[0] in shopping_cart:#判断是否在字典中的方法                    shopping_cart[product[0]] [1] +=1                else:                    shopping_cart[product[0]] = [product[1],1]                salary -= product[1]                print("添加商品" + product[0] +"到购物车", "你现在的余额为" + str(salary))            else:                 print("您的余额不足,产品的价格是" + str(product[1]) + "你还差" + str(product[1] - salary))        else:            print("商品不存在")    elif choice == "q":            print("---------已购买商品列表-------")            id_counter = 1            total_cost = 0        print("id  商品  数量  单价  总价")            for key in shopping_cart:                print("%10s%10s%10s%10s%10s" %(id_counter,                key,                shopping_cart[key][1],                shopping_cart[key][0],                shopping_cart[key][1]*shopping_cart[key][0]))#格式化输出                id_counter +=1                total_cost += shopping_cart[key][1]*shopping_cart[key][0]            print("总花费%s" % (total_cost))            break    else:            print("无此选项")

  

 

#######################################################################

                 

if []:    print"yes"

 

  

空列表,空字典,空元组,空集合,空字符串,0,布尔值都为假,

 

算数运算:

比较运算:

赋值运算:

逻辑运算:

成员运算:

身份运算:

位运算:

 

 

 

 

 

 

 

 

 

menu = {    '北京':{        '昌平':{            '沙河':{                '老男孩':100000            }        }    },    '河南':{}}exit_flag = Falsewhile not exit_flag:#程序开始打印一级菜单    for key in menu:        print(key)    choice = input(">:").strip()#第1次用户选择    if len(choice) == 0:continue    if choice == 'b': break    if choice == 'q':        exit_flag = True        continue#直接退出不再打印下边的内容    if choice in menu:#省级菜单存在,进入下一级        while not exit_flag:            next_layer = menu[choice]            for key2 in next_layer:                print(key2)            choice2 = input(">>:").strip()  # 第2次用户选择            if len(choice2) == 0: continue            if choice2 == 'b': break            if choice2 == 'q':                exit_flag = True                continue            if choice2 in next_layer:#市级菜单存在,进入下一级                while not exit_flag:                    next_layer2 = next_layer[choice2]                    for key3 in next_layer2:                        print(key3)                    choice3 = input(">>>:").strip()  # 第3次用户选择                    if len(choice3) == 0: continue                    if choice3 == 'b': break                    if choice3 == 'q':                        exit_flag = True                        continue                    if choice3 in next_layer2:  # 县级菜单存在,进入下一级                        while not exit_flag:                            next_layer3 = next_layer2[choice3]                            for key4 in next_layer3:                                print(key4)                            choice4 = input(">>>>:").strip()  # 第4次用户选择                            if choice4 == 'b':break                            if choice4 == 'q':                                exit_flag =True                                continue

  

转载于:https://www.cnblogs.com/wanchenxi/p/7216301.html

你可能感兴趣的文章
text-decoration与color属性
查看>>
如何使用Mybatis第三方插件--PageHelper实现分页操作
查看>>
PyCharm搭建GO开发环境(GO语言学习第1课)
查看>>
Android交互
查看>>
提醒我喝水chrome插件开发指南
查看>>
列表数据转树形数据
查看>>
Java新版本的开发已正式进入轨道,版本号18.3
查看>>
从零开始的webpack生活-0x009:FilesLoader装载文件
查看>>
在electron中实现跨域请求,无需更改服务器端设置
查看>>
gitlab-ci配置详解(一)
查看>>
听说你叫Java(二)–Servlet请求
查看>>
案例分享〡三拾众筹持续交付开发流程支撑创新业务
查看>>
FreeWheel业务系统微服务化过程经验分享
查看>>
移动互联网下半场,iOS开发者如何“高薪”成长?
查看>>
Atlassian是怎样进行持续交付的?且听 Steve Smith一一道来
查看>>
Web Storage相关
查看>>
[PHP内核探索]PHP中的哈希表
查看>>
Apache-drill Architechture
查看>>
WordPress 5.2 Beta 3 发布,要求 PHP 5.6.20 以上版本
查看>>
通通连起来——无处不在的流
查看>>