python学习--购物车1

购物车程序,程序要求如下:

    1. 商品信息- 数量、单价、名称

    2. 用户信息- 帐号、密码、余额

    3. 用户可充值

    4. 购物历史信息

    5. 允许用户多次购买,每次可购买多件

    6. 余额不足时进行提醒

    7. 用户退出时 ,输出本次购物信息

    8. 用户下次登陆时可查看购物历史

    9. 商品列表分级

该程序涉及到的知识有:1、条件判断;2、循环应用;3、字典,以及列表的应用;4、文件的读写操作。

先写登录操作部分代码:

#登录操作
username = input("username:")
print("****************************")
password = input("password:")
print("****************************")

i = 1  #加入记数器,记录连续登录失败次数
while i <= 3:    #登录超过三次,锁定账户,在一定时间内不能登录
    if username == "maomao" and password == "123":
        print("welecom to shopping maket")
        break

    elif i == 3:
        print("input more than three times, try again after 2 hours")
        break
    else:
        print("you put an wrong name or password,please input again")

    i += 1
    username = input("username:")
    password = input("password:")

 

posted @ 2017-11-20 21:48  maoxiong  阅读(137)  评论(0编辑  收藏  举报