码迷,mamicode.com
首页 > 编程语言 > 详细

python写注册程序

时间:2017-09-17 19:32:19      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:append   print   username   知识点   斜杠   file   windows   注册   错误   

# 需求分析
# 1.写一个注册的程序,输入username,密码,密码确认,输入的账号和密码不能为空,
# 2.两次输入密码必须一致,用户名不能重复,错误次数是3次
#分析
# 1.输入username,密码,密码确认
# username
# passwd
# c_passwd
# 2.输入的账号和密码不能为空

#3.两次输入密码必须一致

#4.用户名不能重复
# 需要获取存储用户信息的文件并进行比对(新的知识点)同时把注册好的用户信息存储在用户信息存储文件中。
#python 中的斜杠与Windows中的斜杠方向相反
#5.错误次数是3次(完成)

i=0
while True:
file = open(‘C:/username.txt‘, ‘a+‘)
file.seek(0)
users = []
for line in file:
username = line.strip()
users.append(username)
username = input(‘请输入用户名:‘)
passwd = input(‘请输入密码:‘)
c_passwd = input(‘请再次输入密码:‘)

if username == ‘‘ or passwd == ‘‘ or c_passwd == ‘‘:
print("用户名或者密码不能为空或再次确认密码不能为空")
elif c_passwd != passwd :
i+=1
print(‘密码和确认密码不一致‘)
if i==3:
break
elif username in users:
print(‘用户名已经存在‘)
else:
print(‘恭喜你,注册成功!‘)
file.write(username+‘\n‘)
file.close()

python写注册程序

标签:append   print   username   知识点   斜杠   file   windows   注册   错误   

原文地址:http://www.cnblogs.com/zhangmin123456/p/7536683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!