|
username=input('请输入您的注册用户名:')
password=input('请输入您的注册密码:')
with open('list_of_info',mode='w',encoding='utf-8') as f:
f.write('{}\n{}'.format(username,password))
print('恭喜您注册成功')
with open('list_of_info',mode='r+',encoding='utf-8') as f1:
print(f1.readlines()[0],type(f1.readlines()[0]))
count=0
count1=0
username_1=input('请输入您的登录用户名:').strip()
while count<3:
if username_1!=f1.readlines()[1]:
print('请输入的用户名不存在,请重新输入')
count+=1
else:
break
password_1=input('请输入您的登录密码:').strip()
while count<3:
if password_1!=f1.readlines()[1]:
print('您输入的密码错误,请重新输入')
count1=count1+1
else:
break
print('恭喜您登录成功')
运行结果如下:
请输入您的注册用户名:lk请输入您的注册密码:123恭喜您注册成功Traceback (most recent call last): File "F:/python/python学习/人工智能/第一阶段day2/练习.py", line 7, in <module> print(f1.readlines()[0],type(f1.readlines()[0]))IndexError: list index out of rangeProcess finished with exit code 1
print(f1.readlines()[0])能够成功运行,为何加了一个type后就报错呢。
|
|