1. 程式人生 > >用python寫一個簡單的使用者登陸程式(要求寫成函式)

用python寫一個簡單的使用者登陸程式(要求寫成函式)

效能要求:

原始碼:

dict1={}
def log():
    global dict1
    print("|---新建使用者:N/n---|")
    print("|---賬戶登入:E/e---|")
    print("|---退出程式:Q/q---|")
    what=input("|---請輸入指令程式碼:")
    
    if what=='n' or what=='N' :
        key=input("請輸入使用者名稱:")
        while key in dict1 :
            key=input("此使用者名稱已經被使用,請重新輸入")
        value=input("請輸入密碼:")
        dict1[key]=value
        print("註冊成功,趕緊試試登陸把^_^")
            
    elif what=='e' or what=='E':
        key=input("請輸入使用者名稱:")
        while key not in dict1:
            key=input("您輸入的使用者名稱不存在,請重新輸入")
        value=input("請輸入密碼:")
        if(dict1[key]==value):
            print("歡迎進入胯下痛系統,請點選右上角的X結束程式!")
        else:
            print("密碼錯誤")

    elif what=='q' or what=='Q':
        return
    
while(1):
    log()