设为首页 收藏本站
查看: 1237|回复: 0

[经验分享] python学习心得-第一天-作业

[复制链接]

尚未签到

发表于 2018-8-15 13:44:24 | 显示全部楼层 |阅读模式
#__author__ = 'leslie'  
#-*- condig=utf-8 -*-
  

  
#购物车:
  
#1. 商品信息- 数量、单价、名称
  
#2. 用户信息- 帐号、密码、余额
  
#3. 用户可充值
  
#4. 购物历史信息
  
#5. 允许用户多次购买,每次可购买多件
  
#6. 余额不足时进行提醒
  
#7. 用户退出时 ,输出档次购物信息
  
#8. 用户下次登陆时可查看购物历史
  
#9. 商品列表分级显示
  

  
import os
  
import sys
  

  
name_list = {
  
    'caosubo':['123456','9999'],'leslie':['2345','8888']
  
}
  
shop_list = ['家用电器','日用百货','服装鞋帽']
  

  
dianqi = ['电视','洗衣机','电冰箱']
  
yiyongbaihuo = ['洗衣粉','卫生纸','牙膏']
  
cloth = ['男装','女装','童装']
  

  
tv = [('创维',3000),('乐视',4000)]
  
washer = [('海尔',5000),('小天鹅',4500)]
  
icebox = [('海尔',6000),('格力',5500)]
  
detergent = [('雕牌',10),('立白',8)]
  
bumf = [('维达',15),('心相印',15)]
  
toothpaste = [('中华',12),('黑人',15)]
  
cloth_man = [('杉杉',200),('七匹狼',500)]
  
cloth_woman = [('普拉达',5000),('迪奥',10000)]
  
cloth_child = [('小天才',500),('巴拉巴拉',600)]
  

  
a = {'家用电器':dianqi,'日用百货':yiyongbaihuo,'服装鞋帽':cloth}
  
b = {'电视':tv,'洗衣机':washer,'电冰箱':icebox,'洗衣粉':detergent,'卫生纸':bumf,'牙膏':toothpaste,'男装':cloth_man,'女装':cloth_woman,'童装':cloth_child}
  

  
shop_car = {}
  
exit_flag = False
  
count = 0
  

  
while exit_flag is not True:
  
    if count < 3:
  
        username = input("请输入你的姓名:")
  
        password = input("请输入密码:")
  
        if username in name_list:
  
            passwd = name_list[username][0]
  
            salary = int(name_list[username][1])
  
            if password == passwd:
  
                f = open(username,'a')
  
                print ("Welcome".center(40,'-'))
  
                print ("您的账户余额为:%s"%salary)
  
                money = input ("确定是否充值,输入金额,否请输入n:")
  
                if money.isdigit():
  
                    money = int(money)
  
                    salary = salary + money
  
                    print ("你的余额为%s:"%salary)
  
                    break
  
                elif money == 'n':
  
                    break
  
                else:
  
                    print ("请重新输入!")
  
            else:
  
                print ("您的密码有误!请重新输入:")
  
                count += 1
  
        else:
  
            print ("尚未注册")
  
            count += 1
  
    else:
  
        exit()
  
while exit_flag is not True:
  
    print ("商品分类".center(40,'-'))
  
    for item in enumerate(shop_list):
  
        print (item)
  
    first_choice = input ("请输入你的选择:")
  
    if first_choice.isdigit() :
  
        first_choice = int(first_choice)
  
        if first_choice < len((shop_list)):
  
            shop1 = a[shop_list[first_choice]]
  
            print ("商品分类".center(40,'-'))
  
            for item in enumerate(shop1):
  
                print (item)
  
            second_choice = input ("请输入你的选择:")
  
            if second_choice.isdigit():
  
                second_choice = int(second_choice)
  
                if second_choice < len(shop1):
  
                    shop2 = b[shop1[second_choice]]
  
                    print ("商品分类".center(40,'-'))
  
                    for item in enumerate(shop2):
  
                        print (item)
  
                    third_choice = input ("请输入你的选择:")
  
                    if third_choice.isdigit():
  
                        third_choice = int(third_choice)
  
                        if third_choice < len(shop2):
  
                            shop_choice = shop2[third_choice][0]
  
                            number = input ("购买数量:")
  
                            if number.isdigit():
  
                                number = int(number)
  
                                if number > 0:
  
                                    shop_price = shop2[third_choice][1]*number
  
                                else:
  
                                    print ("您的输入有误!")
  
                            else:
  
                                print ("您的输入有误!")
  
                            if salary > shop_price:
  
                                salary = salary -  shop_price
  
                                shop_car[shop_choice] = number
  
                                print (shop_car)
  
                            else:
  
                                print ("你的余额不足!")
  
                                input_money = input ("需要充值吗?请输入金额或是q退出:")
  
                                if input_money.isdigit():
  
                                    input_money = int (input_money)
  
                                    salary = salary + input_money
  
                                    print ("您现在的余额为:%s"%salary)
  
                                elif input_money == 'q':
  
                                    pass
  
                                else:
  
                                    print ("对不起你输入有误!")
  
                        else:
  
                            print ("您的选择有误,请重新选择!")
  
                    elif third_choice == 'q':
  
                        print ("欢迎下次光临!".center(40,'-'))
  
                        print ("您购买的商品如下:%s"%shop_car)
  
                        print ("您的余额为:%s"%salary)
  
                        exit_flag = True
  
                    else:
  
                        print ("您的输入有误!")
  
            elif second_choice == 'q':
  
                print ("欢迎下次光临!".center(40,'-'))
  
                print ("您购买的商品如下:%s"%shop_car)
  
                print ("您的余额为:%s"%salary)
  
                exit_flag = True
  
            else:
  
                print ("您的输入有误!")
  
    elif first_choice == 'q':
  
        print ("欢迎下次光临!".center(40,'-'))
  
        print ("您购买的商品如下:%s"%shop_car)
  
        print ("您的余额为:%s"%salary)
  
        exit_flag = True
  
    else:
  
        print ("您的输入有误!")
  

  
#将购物车信息存储在已用户名命名的文件中
  
f = open(username,'a')
  
bb = str(shop_car)
  
f.write(bb + '\n')
  
f.close()

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-552288-1-1.html 上篇帖子: 源码包安装python2.7.6和ipython1.2.1 下篇帖子: python pip源配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表