hey guys im making a login script and need help. If you dont get the login right then you have to solve a mathmatical problem to get back to the login screen. When you do get it right then it gives you the username and password. But heres my problem if you get it wrong then it sends you back to the login screen where you enter your username and password this is not what i want.How would i make it where if you got it wrong it would just ask you to try again. thanks in advance
while True:
username = raw_input('Username: ')
password = raw_input('Password: ')
if username == 'Uname' and password == 'Pword':
print 'Welcome,'
raw_input("press any key to exit")
break
else:
problem = 22
while problem == 22:
problem = int(raw_input('ERROR ACCESS DENIED, Solve to lift quarantine\n(7 * 3) - 3 + 4: '))
if problem == 22:
print ('Quarantine lifted, username is Uname and password is Pword')
break
else:
print ('invalid')
2 replies to this topic
#1
Posted 21 January 2011 - 06:37 PM
|
|
|
#2
Posted 24 January 2011 - 02:27 PM
Sorry ahead of time, I am very new to python, but why don't you try using a dictionary set for the user names and passwords? what if you had 15 users, would you really want to do
if username == 'Uname' and password == 'Pword':
inside your program?
and what if one user wanted to change his/her password. You would then have to find it in the program everywhere it is located, including here
print ('Quarantine lifted, username is Uname and password is Pword')
and change the password.
and what about adding a new user? etc?
if username == 'Uname' and password == 'Pword':
inside your program?
and what if one user wanted to change his/her password. You would then have to find it in the program everywhere it is located, including here
print ('Quarantine lifted, username is Uname and password is Pword')
and change the password.
and what about adding a new user? etc?
Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!
#3
Posted 24 January 2011 - 02:38 PM
#1494316 - Pastie
and the while problem==22 loop will not loop if the user enters lets say, the number 20 (any number besides 22), the program will just repeat.
and the while problem==22 loop will not loop if the user enters lets say, the number 20 (any number besides 22), the program will just repeat.
Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









