Day2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Day2相关的知识,希望对你有一定的参考价值。

Day2

第二天的内容主要是学习数据类型、bytes数据类型、列表、字符串的常见操作、字典的使用等。期间,练习了购物车程序与三级菜单。

1.首先是各种数据类型的判断

 技术分享

技术分享

 

 

 

2.Bytes strings

 技术分享

 

:这是一个编码解码的过程。

  1. Sys.os的简单介绍应用

 技术分享

技术分享

 

 

 

4.列表常见操作

 技术分享

 

 

 

 

5.字典的使用

 技术分享

技术分享

 

6.简单的菜单制作

技术分享

 

 

7.接下来就是简单的购物车程序练习跟三级菜单练习

____Author____  = "Tete"


product_list = [
    [‘Apple‘,10],
    [‘Banner‘,6],
    [‘Peach‘,12],
    [‘Orage‘,14],
    [‘Grape‘,11]
]
shopping_list = []
salary = input("请输入你的余额:")
if salary.isdigit():
    salary = int(salary)
    while True:
        for index, item in enumerate(product_list):
            print(index,item)
        user_choice = input("请输入商品的编号:")
        if user_choice.isdigit():
            user_choice = int(user_choice)
            if user_choice < len(product_list) and user_choice >= 0:
                p_item = product_list[user_choice]
                if p_item[1] < salary:
                    shopping_list.append(p_item)
                    salary -= p_item[1]
                    print("您购买的%s已加入购物车,余额剩余:\\033[31;1m%s\\033[0m" %(p_item,salary))
                else:
                    print("\\033[41;1m你的余额不足!\\033[0m")
            else:
                print("找不到相应的商品编号!")
        elif user_choice == ‘q‘:
            print("购物车内的商品如下:%s\\n您的余额剩余:%s" %(shopping_list,salary))
            for i in shopping_list:
                print(i)
            exit()
        else:
            print("您输入的选项错误!")
else:
    print("Error!")

----------------------------三级菜单--------------------------------

places = {
    ‘福建‘:{
        "厦门":{
            "翔安":["翔安隧道","翔安小吃"],
            "湖里":["湖里公园","湖里特产"],
            "集美":["集美大学","集美大桥"]
        },
        "泉州":{"水头":["水头狮子"]},
        "漳州":{"漳浦":["漳浦咸水鸭"]}
    },
    ‘北京‘:{
        "朝阳":{
            "望京":["奔驰","陌陌"],
            "国贸":["CICC","HP"],
            "东直门":["Advent","飞信"]
        },
        "顺义":[],
        "海淀":[],
    },
    ‘广东‘:{
        "东莞":{
            "翔安":["翔安隧道","翔安小吃"],
            "湖里":["湖里公园","湖里特产"],
            "集美":["集美大学","集美大桥"]
        },
        "济南":[],
        "德州":[],
    }
}

flag = True
while flag:
    for i in places:
        print(i)
    choice = input(">>>选择进入1:")
    if choice in places:
        while flag:
            for i2 in places[choice]:
                print("\\t",i2)
            choice2 = input(">>>选择进入2:")
            if choice2 in places[choice]:
                        while flag:
                            for i3 in places[choice][choice2]:
                                print("\\t\\t",i3)
                            choice3 = input(">>>选择进入3:")
                            if choice3 in  places[choice][choice2]:
                                while flag:
                                    for i4 in places[choice][choice2][choice3]:
                                        print("\\t\\t",i4)
                                    choice4 = input(">>>最后一层,按b返回,按q退出:")
                                    if choice4 == ‘b‘:
                                        break
                                    elif choice4 == ‘q‘:
                                        flag = False
                            if choice3 == ‘b‘:
                                 break
                            elif choice3 == ‘q‘:
                                flag = False
            if choice2 == ‘b‘:
                 break
            elif choice2 == ‘q‘:
                 flag = False

Ps:程序就是一层嵌套一层,就成了菜单啦,地名没有完整写规范,主要练习一下。

    

 

技术分享




































































































以上是关于Day2的主要内容,如果未能解决你的问题,请参考以下文章

Day2

day2

day2

日报-day2

day2

$CSP$ $2019$ $Day2$ 模拟考试 题解报告