无论何时输入的密码是错误的,它都会显示“错误的尝试次数”。然而,当我的电子邮件是错误的,它会给我一个错误的消息,而不是一个错误的密码一样的事情。我尝试为电子邮件构建另一个if循环,但没有成功。你知道吗
错误是:
Traceback (most recent call last):
File "E:\Theater.py", line 126, in <module>
TheaterFileLogin()
File "E:\Theater.py", line 56, in TheaterFileLogin
Emaildex = Emails1.index(Email)
ValueError: 's,dm' is not in list
代码是:
import csv
x=0
while x<3:
with open('Theater.csv', 'r') as csvfile:
Theater = csv.reader(csvfile, delimiter=",")
Emails1 = []
Passwords1 = []
Passwords2 = []
Passwords3 = []
Passwords4 = []
Firstnames = []
Surnames = []
for row in Theater:
Firstname = row [1]
Surname = row [0]
Email1 = row[2]
Password1 = row[7]
Password2 = row[8]
Password3 = row[9]
Password4 = row[10]
Firstnames.append(Firstname)
Surnames.append(Surname)
Emails1.append(Email1)
Passwords1.append(Password1)
Passwords2.append(Password2)
Passwords3.append(Password3)
Passwords4.append(Password4)
Email = input("Email Adress: ")
Password = input("Password: ")
Emaildex = Emails1.index(Email)
thepassword = Passwords1[Emaildex]
adminlevel1password = Passwords2[Emaildex]
adminlevel2password = Passwords3[Emaildex]
adminlevel3password = Passwords4[Emaildex]
FN = Firstnames[Emaildex]
SN = Surnames[Emaildex]
if thepassword == Password:
print("Welcome")
x=5
else:
print("Incorect email or password try again")
x+=1
print("Attempt",x)
当您试图查找列表中不存在项的索引时,会得到一个} ^{} ,但是测试
ValueError
。有两种处理方法那个。你呢可以将Emails1.index(Email)
放入^{
Email
是否在Emails1
中更简单。你知道吗下面是代码的一个改进版本,它应该做你想做的事情。请注意,我使用
'rb'
模式打开CSV文件,正如the docs中建议的那样,尽管在python3中这并不是严格必要的。你知道吗相关问题 更多 >
编程相关推荐