python index out of range_list index out of range

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后就报错呢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值