if I have 2 arrays, 1 for username and 1 for password. How can I check username[0] is == to password[0] and so on for all the numbers in the array? So far the code looks like this:
username_aray = ["tina", "john", "kath", "lina", "luke", "ali"]
password_aray = ["tr.35", "sj.34", "kj.45", "kfj.67", "xdjbh.20", "djmv.92"]
username = input("Please enter in your username: ")
if username in username_aray:
print("username found! ")
else:
print ("Invalid Username!! ")
password = input("Please enter in your password: ")
if password in password_aray:
if both ==[]:
print(correct password")
else:
print ("Invalid Password!! ")
else:
print("Invalid Password! ")
With the following code it doesn't recognize body as I haven't defined it and I don't know how to check if username entered matches the password (keeping in mind that username index 0 and password index 0 match each other).
It looks like you should use a dictionnary but if the use of list is mandatory you could do something like that :
username = input("Please enter in your username: ")
if username in username_aray:
print("username found! ")
else:
print ("Invalid Username!! ")
password = input("Please enter in your password: ")
if password == password_aray[username_aray.index(username)]:
print("correct password")
else:
print("Invalid Password! ")
your_list.index(elem)
return the index of elem in the list (if present). Which allow you to test if the element at the same index in another list is the same.