首页 > 代码库 > 第2周作业1

第2周作业1

1.优化购物程序,购买时允许用户选择购买多少件,

2.允许多用户登录,下一次登录后,继续按上次的余额继续购买 ,可以充值 (每个用户有独立的保存文件)

3.允许用户查看之前的购买记录(记录要显示商品购买时间)

4.商品列表分级展示,比如:

  第一层菜单:

  1.家电类

  2.衣服类

  3.手机类

  4.车类

  ...

  选择一个,车类,进入第2层

  1。BMW X3 33333

  2.Audi Q5 33333

  3.Pasate 33335

  4.Tesla Model_3 430000

  5.Tesla Model S 888888

 5.显示已购买商品时,如果有重复的商品,不打印多行,而是在一行展示,如

  id   p_name        num    total_price

        1.  TeslaModelS   2         3434343434

   2.  Coffe        2   60

   3. Bike         1         700

###

Blog一定要写

readme一定要写

流程图 一定画

一定不要copy

会用到 文件 ,datetime模块,json

技术分享

 

#!/usr/bin/env python
# -*-coding:utf-8-*-
# __author__="Liudong"
product_list = {
    ‘家电类‘: [(‘乐视电视‘, 7000), (‘海尔冰箱‘, 5000), (‘小天鹅洗衣机‘, 2000)],
    ‘衣服类‘: [(‘西装‘, 8000), (‘休闲夹克‘, 2000), (‘运动服‘, 800)],
    ‘手机类‘: [(‘Iphone7‘, 7000), (‘小米Note‘, 2000), (‘华为‘, 1000)],
    ‘车类‘: [(‘奔驰ML‘, 800000), (‘特斯拉‘, 700000), (‘奥迪Q7‘, 750000)]
}
def purchase_pro():
    pass
shop_car = []
welcom_msg=‘Welcome to Shopping Home‘.center(50,‘-‘)
print(welcom_msg)
for i in range(3):
    username = input(‘Please input your username:[q=quit]‘)
    if username == ‘q‘:
            exit()
    user_account = open(‘user_info.txt‘, ‘r‘)
    user_account_list = user_account.readlines()
    #print(user_account_list)
    for user_name in user_account_list:
        (user_infile,pass_infile,amount_infile)=user_name.strip(‘\n‘).split()
        # print(user_name.strip(‘\n‘).split())
        # user_name_infile=user_name.strip().split()[0]
        # print(user_name_infile)
        if username == user_infile:
            j = 0
            while j < 3:
                password = input(‘Please input your password:‘)
                if password == pass_infile:
                    print(‘login successed! Have a happy shopping Time!‘)
                    while True:
                        print(‘1.查看购买记录\n2.充值\n3.查询余额\n4.查看购物车\n‘)
                        user_want=input(‘What do you do?‘)
                else:
                    print(‘Invalid username or password...‘)
                    print(‘this is the %d time(s)‘ % (j + 1))
                j += 1
            else:
                print(‘Forget password? Please send a mail to Administrator,bye‘)
                user_account.close()
                exit()
salary=input("Input your salary:")
if salary.isdigit():
    salary=int(salary)
else:
    exit("Invalid data type...")

 

第2周作业1