ITPub博客

首页 > 应用开发 > > list index out of range

list index out of range

作者:lgchen 时间:2019-09-09 10:21:45 0 删除 编辑

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

print(f1.readlines()[0],type(f1.readlines()[0]))

IndexError: list index out of range

Process finished with exit code 1

print(f1.readlines()[0])能够成功运行,为何加了一个type后就报错呢。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1276/viewspace-3123985/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: javasript基础
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    115
  • 访问量
    1025