Hey guys trying to make a login screen where if you dont get the username and password right you have to solve a mathmatical problem and until you get it right it will not let you retry the login.I have it almost but whenever you solve the problem it doesnt matter what you put for the answer it just goes back to the login screen. Here is some of my code
while True:
username = raw_input('Username')
password = raw_input('Password')
if username == 'uname' and password == 'pword':
print ('welcome')
else:
print 'invalid'
problem = raw_input('7 + 4')
if problem == [11]:
login in screen help
Started by BRUTAL, Jan 11 2011 05:25 PM
4 replies to this topic
#1
Posted 11 January 2011 - 05:25 PM
|
|
|
#2
Posted 13 January 2011 - 01:50 PM
Seems easy enough to fix. Assuming you just want a result from your else branch then instead of taking a string as your input, change it to a numeric input. Thus the code would be...
username = raw_input('Username')
password = raw_input('Password')
if username == 'uname' and password == 'pword':
print 'welcome'
else:
print 'invalid'
problem = input('7 + 4')
if problem == 11:
....etc
username = raw_input('Username')
password = raw_input('Password')
if username == 'uname' and password == 'pword':
print 'welcome'
else:
print 'invalid'
problem = input('7 + 4')
if problem == 11:
....etc
#3
Posted 13 January 2011 - 04:20 PM
that still doesnt help my loop problem whenever your doing the problem then you can enter anything and it will still let on to the login screen
#4
Posted 13 January 2011 - 04:25 PM
Ah! I think I get what you mean now... sounds like your executing the code regardless of the condition of your if statement, right? In which case you need to only call the code if the if statement is true...
#5
Posted 13 January 2011 - 04:49 PM
Sweet thanks man umm how would i do that; something about if true right?


Sign In
Create Account


Back to top









