1. 程式人生 > >學習筆記-登入-總是報錯,不知道哪的問題

學習筆記-登入-總是報錯,不知道哪的問題

import os

jd_user_path = 'jd_users.txt'
jd_wx_path = 'wx_users.txt'
user_status = False


def allinlogin(filepath):
    with open(filepath, 'r') as file:
        users = file.readlines()
        username = input("請輸入使用者名稱:")
        password = input("請輸入密碼:")
        for i in users:
            nameandpass 
= i.split(',') if username == nameandpass[0] and password == nameandpass[1]: print("登入成功") user_status = True return True print("使用者名稱或密碼錯誤!") return False def jd_login(): allinlogin('jd_users.txt') def wx_login(): allinlogin(
'wx_users.txt') def user_login(): def login(auth_type = 'jingdong'): if user_status: if auth_type == 'jingdong': jd_login() elif auth_type == 'weixin': wx_login() return login @user_login() def jd_home(auth_type): print("
welcome jd home...") @user_login() def jd_finance(auth_type): print("welcome jd finance...") @user_login() def jd_book(auth_type): print("welcome jd book...") while True: print("1.Home") print("2.finance") print("3.book") user_select = input(">>") if user_select == '1': jd_home('jingdong') elif user_select == '2': jd_finance('weixin') elif user_select == '3': jd_book('weixin') else: print("選擇錯誤,請重新選擇") continue