Jump to content

login in screen help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
BRUTAL

BRUTAL

    Newbie

  • Members
  • PipPip
  • 22 posts
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]:

#2
Christopher87

Christopher87

    Newbie

  • Members
  • PipPip
  • 20 posts
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

#3
BRUTAL

BRUTAL

    Newbie

  • Members
  • PipPip
  • 22 posts
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
Christopher87

Christopher87

    Newbie

  • Members
  • PipPip
  • 20 posts
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
BRUTAL

BRUTAL

    Newbie

  • Members
  • PipPip
  • 22 posts
Sweet thanks man umm how would i do that; something about if true right?