2017-07-31 3 views
0

ユーザがアカウントを持っていない場合にアカウントを作成できるようにしたいのですが、そうした場合、ログインしてユーザ名とパスワードをチェックすることができます彼らがアカウントを作ったときに このコードはサインアップでは動作しますが、ログインした人が既にアカウントを作成している場合はチェックしません。ログインまたはサインアッププログラムpython

import os.path 
if os.path.exists("username"): 
    login() 
    else: 
     make_account() 

def make_account 

filename = ("username"); 
with open (filename, "w") as f: 
    f.write (input("Enter a username: ")); 

filename = ("password"); 
with open (filename, "w") as f: 
    f.write (input("Enter a password: ")); 


def login 
username = input("Enter your username: ") 
password = input("Enter your password: ") 
check() 

def check 
if username == open("username").read(): and 
passsword == open("password").read(): 
    print("Successful login") 
else: 
    print('Incorrect') 
+2

とは?間違いましたか?コードに問題がある場合は、質問を編集してください。 – Zcode

+1

関数を定義するための構文はわかりますか? –

+0

あなたの質問は何ですか? – ranieribt

答えて

0

これを試してみてください:

import os.path 
if os.path.exists("username"): 
    login() 
else: 
    make_account() 

def make_account(): 

    filename = ("username"); 
    with open (filename, "w") as f: 
     f.write (input("Enter a username: ")); 

    filename = ("password"); 
    with open (filename, "w") as f: 
     f.write (input("Enter a password: ")); 


def login(): 
    username = input("Enter your username: ") 
    password = input("Enter your password: ") 
    check() 

def check(): 
    if username == open("username").read() and passsword == open("password").read(): 
     print("Successful login") 
    else: 
     print('Incorrect') 
+0

作品が、再び走って起動したとき:チェック 場合には、)(ログイン チェックでは、 ログイン() ライン16には、 ライン27 ライン19:トレースバック(最新の呼び出しの最後) read(): NameError:name 'username'は定義されていません。username == open( "username")。 –

関連する問題