Help with Basic Python Coding

Daniel Parchebaf

Estimable
Sep 18, 2014
3
0
4,510
0
Hello, i am a beginner programer using python, how can i make python understand multiple passwords, here is an example of what i mean:

password = input ("Enter Password to " \
"enter terminal: ")

if password == "Cyndi": -------here is where i need it to understand more than 1 password
print ("Access Granted ")

else:
print ("Access Denied")
print ("Contact System Administrator ")
input ("Press exit")
 

ex_bubblehead

Distinguished
Moderator
This is looking more and more like a class assignment so I'm going to decline to simply hand you an answer.

What you need to do is open the text file within your script and read it line by line until either a match is found or the end of the file is reached without finding a match. Place that code in a function that takes the password as a parameter and returns pass/fail as a return value, then act on that as necessary.
 

Daniel Parchebaf

Estimable
Sep 18, 2014
3
0
4,510
0


im sorry, i didnt make it clear, i want to make python accept more than 1 password, so instead of just "Cyndi" i can have another password it will recognize at the same time
 

ex_bubblehead

Distinguished
Moderator
That's what the text file is for. You can put as many as you want in it and scan as necessary. That's the proper way to do it. Placing them in your code means changing the script every time a password changes.
 

Daniel Parchebaf

Estimable
Sep 18, 2014
3
0
4,510
0


ok could you explain in detail what i have to do
 

ex_bubblehead

Distinguished
Moderator
This is looking more and more like a class assignment so I'm going to decline to simply hand you an answer.

What you need to do is open the text file within your script and read it line by line until either a match is found or the end of the file is reached without finding a match. Place that code in a function that takes the password as a parameter and returns pass/fail as a return value, then act on that as necessary.
 

simonCode

Estimable
Dec 5, 2014
1
0
4,510
0
Hello,

your problem is, that function input() finding a variable in your script.
If you type Cyndi as argument in input(), script start finding a variable name Cyndi.
You have to use raw_input() function, that return what you expect.

fix:
password = raw_input(Enter Password to " \
"enter terminal: ")
 
Thread starter Similar threads Forum Replies Date
F Apps General Discussion 2
K Apps General Discussion 4
R Apps General Discussion 2
V Apps General Discussion 1
G Apps General Discussion 0
Wayfall Apps General Discussion 2
C Apps General Discussion 2
M Apps General Discussion 1
E Apps General Discussion 1
Rainfire Apps General Discussion 3
R Apps General Discussion 1
RAZER Gamer Apps General Discussion 2
Cathroad Apps General Discussion 1
RAZER Gamer Apps General Discussion 3
X Apps General Discussion 6
H Apps General Discussion 1
P Apps General Discussion 16
M Apps General Discussion 1
K Apps General Discussion 2
V Apps General Discussion 4

ASK THE COMMUNITY