我正在创建一个登录和菜单程序,我有一个 CSV 文件,其中包含我发明的一些用户的登录名和密码。当我运行程序时,它没有任何错误,但是当我输入正确的用户名和密码时,它不能正常工作。
当我的代码应该打印“已授予访问权限”时,它会打印“未授予访问权限”。
这是我在控制台中打印 CSV 时的样子:
[['Username' 'Password' 'Access Level'] ['booker12' '12se74' '1'] ['grey07' '04ap67' '1'] ['johnson81' '30no86' '1'] ['jenkins46' '14ju73' '1'] ['smith79' '09ja61' '1'] ['ccastrej' 'superuser03' '3'] ['ssofia' 'semigod1' '2'] ['isabella' 'payasian' '2'] ['pablitohesk' 'soccer13' '2'] ['teacher' 'igradethis100' '3'] ['pedrocorte' 'asturiano' '1'] ['andrea' 'jesusito' '1']]
这是我现在拥有的代码:
import sys
import csv
import numpy as np
def Main():
login()
def login():
with open('MatrixAccess.csv') as csvfile: #I import the csv file
reader = csv.reader(csvfile, delimiter = ';') #I read through it
x = list(reader) # I convert the csv into an array to loop through it easier with the numpy library
print(np.matrix(x)) #I print it to check if I imported it correctly
print("Username: ")
str1 = input()
print("Password: ")
str2 = input()
for i in [2]:
for j in [i]: #I have to convert the ints to lists so I can iterate through the list
if(str1 == x[i][j] and str2 == x[i][j+1]):
print("Access granted")
else:
print("Access not granted")
def menu():
print("************MAIN MENU**************")
杨__羊羊
相关分类