设为首页 加入收藏

TOP

Python模块列表字典(五)
2019-09-14 00:51:51 】 浏览:232
Tags:Python 模块 字典
                choice4 = input("最后一层,按b返回>>:")
                        if choice4 == "b":
                            pass
                        elif choice4 == "q":
                            exit_flag = True
                    if choice3 == "b":
                        break
                    elif choice3 == "q":
                        exit_flag = True
            if choice2 == "b":
                break
            elif choice2 == "q":
                exit_flag = True


 


十一、作业


购物车
用户入口:
1、商品信息存在文件里
2、已购商品,余额记录


商家入口:
2、可以添加商品,修改商品价格


 


#!/usr/bin/env python
# -*- coding:utf-8 -*-
# 用户或者是商家
# 用户-登陆信息-卡里剩多少钱-打开商品列表-选择商品-打印已购商品,余额记录
# 商家-登陆信息-添加商品/修改商品价格-存入文件
user_info = {"zhangsan":[333333,30000],"lisi":[444444,40000],"wangwu":[555555,50000]}
shopper_info = {"hhh":666666}
user = input("user:")
password = input("password:")
shopping_list = []
product_list = open("product_list.txt").readlines()
if user in user_info and int(user_info[user][0]) == int(password):
    salary = int(user_info[user][1])
    print("Welcome %s to our shopping center!Your salary is %s" % (user, salary))
    while True:
        for k, v in enumerate(product_list):
            print(k, v)
        choice = input("Which product do you want to select?")
        shopping_list.append(product_list[int(choice)])
        shop_price = int(product_list[int(choice)].split(":")[1])
        salary -= shop_price
        print("Your shopping_list is %s and your salary is %s" % (shopping_list, salary))
        choice2 = input("Do you want to continue to shopping?")
        if choice2 == "n":
            print("Welcome to you next time!Your shopping_list is %s and your salary is %s" % (shopping_list, salary))
            break
        elif choice2 == "y":
            pass
elif user in shopper_info and int(shopper_info[user]) == int(password):
    while True:
        print("1 add product\n""2 modify price")
        choice3 = input("What do you want to do?")
        if choice3 == "1":
            product = input("Which product do you want to add?")
  &nbs

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python 常用模块详解 下一篇Python PIL库图像处理操作详解

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目