购物车模板

db.txt

zhzhang01,123,1000
zhzhang02,123,1000
zhzhang03,123,1000
zhzhang04,123,1000
zhzhang05,123,1000
zhzhang06,123,1000
zhzhang07,123,1000

 

登录模块

import os
def login():
    tag = True
    count = 3
    while tag:
        if count == 0:
            print('错误次数超过三次,系统已锁定')
            tag = False
            break
        inp_username = input('请输入用户名:').strip()


        with open('db.txt','r',encoding = 'utf-8') as f:
            for line in f:
                line.strip('\n')
                user_info = line.split(',')

                uname_of_db = user_info[0]
                pwd_of_db = user_info[1]
                balance_of_db = int(user_info[2])
                if uname_of_db == inp_username:
                    inp_pwd = input('请输入密码:').strip()
                    if uname_of_db == inp_username and pwd_of_db == inp_pwd:
                        print('用户登录成功')
                        # 将用户信息存储到用户信息列表
                        current_userinfo = [uname_of_db, balance_of_db]
                        print('尊敬的用户[%s],您的余额为[%s],祝您购物愉快' % (uname_of_db, balance_of_db))
                        tag = False
                        break
                    if uname_of_db != inp_username and pwd_of_db == inp_pwd:
                        count -= 1
                        print('用户名输入错误')
                        print('一共只有三次试错机会哦,剩余次数:%s' % (count-1))
                        break
                    if uname_of_db == inp_username and pwd_of_db != inp_pwd:
                        count-=1
                        print('密码输入错误')
                        print('一共只有三次试错机会哦,剩余次数:%s' % (count-1))
                        break
            else:
                print('用户名不存在!!!')
                print('一共只有三次试错机会哦,剩余次数:%s' % (count-1))
                count -= 1

 

注册模块

def register():
    username = input('请输入注册姓名:').strip()
    while True:
        pwd1 = input('请输入注册密码:').strip()
        pwd2 = input('请再次输入确认密码:').strip()
        if pwd1 == pwd2:
            break
        else:
            print('两次输入的密码不一致,请重新输入!!!')
    while True:
        balance = input('请输入充值金额:').strip()
        if balance.isdigit():
            break
        else:
            print('非法输入!!!')
    with open('db.txt',mode='a',encoding = 'utf-8') as f:
        f.write('%s,%s,%s\n' %(username,pwd1,balance))
    print('注册成功')

 

 


 

上一篇:全选和反选(复选框)


下一篇:2019.7.31学习内容及笔记