我正在尝试编写一个函数,该函数将了解如何使用一个用户名但多个密码登录。
import sys
def login():
username = raw_input('username')
password = raw_input('password')
if username == 'pi':
return password
# if the correct user name is returned 'pi' I want to be
# prompted to enter a password .
else:
# if 'pi' is not entered i want to print out 'restricted'
print 'restricted'
if password == '123':
# if password is '123' want it to grant access
# aka ' print out 'welcome'
return 'welcome'
if password == 'guest':
# this is where the second password is , if 'guest'
# is entered want it to grant access to different
# program aka print 'welcome guest'
return 'welcome guest'
这是我运行该功能时得到的。
>>> login()
usernamepi
password123
'123'
应该返回“欢迎”
>>> login()
usernamepi
passwordguest
'guest'