-
Python (
http://www.daniweb.com/forums/forum114.html)
| tondeuse34 | May 16th, 2008 9:28 pm | |
| Lists & Passwords Hey guys, I've came across problem and wondering say if you have a 2 lists called user_list and pass_list and you have a prompt for username and password. Instead of 1 user name and password how could it be for all can be used at the same prompt? heres an example of my code: #Start of the program
print "Welcome To the Server!"
#Varible i'm using for later on in the program
a = 0
#The list of user names
user_list = ['sam','bob','tom']
#And list of passwords
pass_list1 = ['12','13','14']
#The prompt ofr the username and password
username = raw_input("Username: ") % user_list
if username =='user_list':
password = raw_input("Password: ") % pass_list1
if password.lower() == 'pass_list1': |
| Capt.Micro | May 17th, 2008 12:03 am | |
| Re: Lists & Passwords Hello, Looking at your code, you only need one thing changed, the if parts part.
#Start of the program
print "Welcome To the Server!"
#Varible i'm using for later on in the program
a = 0
#The list of user names
user_list = ['sam','bob','tom']
#And list of passwords
pass_list1 = ['12','13','14']
#The prompt ofr the username and password
username = raw_input("Username: ")
for user in user_list:
if username == user:
password = raw_input("Password: ")
for pass in pass_list1:
if password.lower() == pass:
<insert rest of code here>
If you have any more questions, just ask. |
| a1eio | May 17th, 2008 7:42 am | |
| Re: Lists & Passwords python has a keyword function in that would be useful in your example.
if password in pass_list1:
# do something |
| tondeuse34 | May 17th, 2008 10:58 am | |
| Re: Lists & Passwords Thanks guys for answering my question :) |
| tondeuse34 | May 17th, 2008 11:35 am | |
| Re: Lists & Passwords also, another quick question why does it print one thing 3 times? |
| All times are GMT -4. The time now is 2:52 am. | |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC