私は1つのユーザー名で複数のパスワードを使ってログインする方法を理解する関数を書こうとしています。Python: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'
これは私が機能を実行するときに得られるものです。ユーザー名としてpi
を入力するときに入力したパスワードを返す:
>>> login()
usernamepi
password123
'123'
は、あなたがそれを言うかを正確にやっている「歓迎」
>>> login()
usernamepi
passwordguest
'guest'
ので、我々は何を理解することができ、コードのタグを使用して書式設定を修正してください続行中です。 – utdemir
ごめんなさい。それは私の最初の投稿 – PythagorasPi