Ok, I'm pretty new to Python....
What I need to do is set up a couple tuples like so:
users = ('user1','user2','user3')
passw = ('pass1','pass2','pass3')
I then am asking the user for their username and password to compare to the tuples. The only way I could think to do that was converting the tuples to list and using the index() then assigning that index to a var and the converting it back to a tuple:
users = list(users)
passw = list(passw)
ind1 = users.index(user_in)
ind2 = passw.index(passw_in)
users = tuple(users)
passw = tuple(passw)
then using an if/else print the necessarily things, but this just seems a little arbitrary....redundant... I dont know, something...Is there an easier way to go about?
This is my entire script so far:
#------------------------------
users = ('user1','user2','user3')
passw = ('pass1','pass2','pass3')
#----------------------------
user_in = raw_input('Username? ')
passw_in = raw_input('Password? ')
#-----------------------------------
if not (user_in in users):
new_user = raw_input('User "%s" not found - would you like to enroll? ' %user_in)
if new_user == ('y' or 'Y'):
users = list(users)
passw = list(passw)
users.append(user_in)
passw.append(passw_in)
users = tuple(users)
passw = tuple(passw)
#-----------------------------------------------
if user_in in users:
users = list(users)
passw = list(passw)
ind1 = users.index(user_in)
ind2 = passw.index(passw_in)
users = tuple(users)
passw = tuple(passw)
if ind1 == ind2:
print('Match')
elif ind1 != ind2:
print('Not Match'
)
It seems to work except if when the user puts in a non registerd username and decides let say "n" to enroll it still assigns ind1 and ind2 the value 3 and prints "Match"
Thanks for any help