This function won't do what you think, because you are returning after the first check, so it will just keep asking for the name and when the user enters Bob
, nothing will happen because you aren't doing anything with the result.
Since you are overwriting whatever username and password you are passing in to the function, it will always check for Bob
and not what you ask it to check for.
Try this version instead:
def firstlogin(user, passwd):
''' A function to check the username
and password for a user '''
x = raw_input('Enter Name: ')
if x == user:
y = raw_input('Great! Now try guessing the password: ')
if y == passwd:
print 'Correct!'
else:
print 'Sorry, password was wrong'
else:
print 'Sorry, username was wrong'
Save it to a file, lets say my_func.py
, then in another file in the same directory, type:
from my_func import firstlogin
firstlogin('user','sekret')
Or you can type python
to get to the interactive prompt, again from the same directory where you saved my_func.py
:
>>> from my_func import firstlogin
>>> firstlogin('user','sekret')