1つのユーザー名と複数のパスワードを使用してログインする方法を理解する関数を作成しようとしています。
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'