第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何調(diào)試Python代碼中的名稱錯誤

如何調(diào)試Python代碼中的名稱錯誤

繁星coding 2023-10-25 10:49:58
我正在嘗試制作一個登錄系統(tǒng),但阻止我的是我無法調(diào)試的名稱錯誤know = input("Do you want to signup or log-in \n for signup  enter (s) \n for log-in enter (l):")if know == "s":    user_signup = input("Enter username:")    user_signup2 = input("Enter password: ")    user_signup3 = int(input("Enetr Age:"))theinfo = [user_signup , user_signup2,user_signup3]if know =="l":    login = input("Enter username: ")    user_login2 = input("Enter password:")elif login in theinfo and user_login2 in theinfo:    print("Log in seccefull")elif login not in theinfo or user_login2 not in theinfo:    print("username or password incorect")這是我發(fā)現(xiàn)的錯誤:Traceback (most recent call last):  File "E:\code\gg\.vscode\login.py", line 11, in <module>    elif login in theinfo and user_login2 in theinfo:NameError: name 'login' is not defined
查看完整描述

2 回答

?
慕標(biāo)5832272

TA貢獻1966條經(jīng)驗 獲得超4個贊

know = input("Do you want to signup or log-in \n For signup  enter (s) \n For log-in enter (l):")


if know == "s":

    user_signup = input("Enter username:")

    user_signup2 = input("Enter password: ")

    user_signup3 = int(input("Enter Age:"))


theinfo = [user_signup, user_signup2, user_signup3]


print()

know = input("Do you want to signup or log-in \n For signup  enter (s) \n For log-in enter (l):")

print()


if know == "l":

    login = input("Enter username: ")

    user_login2 = input("Enter password:")


    if login in theinfo and user_login2 in theinfo:

        print("Log in successful")

    elif login not in theinfo or user_login2 not in theinfo:

        print("username or password incorrect")

NameError意味著該變量之前沒有定義。您為程序設(shè)置條件的方式是錯誤的。我已經(jīng)修正了程序。


查看完整回答
反對 回復(fù) 2023-10-25
?
斯蒂芬大帝

TA貢獻1827條經(jīng)驗 獲得超8個贊

使用 if / elif,將讀取零個或一個代碼段。讓我們看看你的 if / elif / elif 代碼:


if know =="l":

    login = input("Enter username: ")

    user_login2 = input("Enter password:")

elif login in theinfo and user_login2 in theinfo:

    print("Log in seccefull")

elif login not in theinfo or user_login2 not in theinfo:

    print("username or password incorect")

如果用戶輸入“l(fā)”,則設(shè)置登錄。但是,接下來的兩個“elif”部分將被跳過。你可以這樣解決這個問題:


if know =="l":

    login = input("Enter username: ")

    user_login2 = input("Enter password:")

    if login in theinfo and user_login2 in theinfo:

        print("Log in seccefull")

    elif login not in theinfo or user_login2 not in theinfo:

        print("username or password incorect")

那么,這就回答了問題。然而,由于多種原因,該代碼仍然無法按預(yù)期工作。但是,您主要缺少一個用于存儲完整用戶集的憑據(jù)列表。您沒有現(xiàn)有用戶的憑據(jù),因此無法檢查返回用戶的用戶名和密碼。您也不能將新用戶的憑據(jù)保存到現(xiàn)有用戶列表中。


know = input('Do you want to signup or log-in \n for signup, enter (s) \n for log-in, enter (l): ').upper()


# Start with a fetch of existing users.

# I am hard-coding users to keep the example simple.  

# Don't do this in your actual code.  You can use something

# like a simple file (though you should not store clear text

# text passwords in a text file. 

# https://www.w3schools.com/python/python_file_handling.asp

credentials = [['Phil', 'my_Password', 37], ['jose', 'espanol', 19]]


the_info = []


if know == 'S':

    user_signup = input('Enter username:')

    user_signup2 = input('Enter password: ')

    user_signup3 = int(input('Enter age:'))

    the_info = [user_signup , user_signup2, user_signup3]

    # The next line save the new user in memory.  

    # Add code to save the info to a file or database. 

    credentials += the_info

    print('Thanks for signing up.')

elif know =='L':

    login = input('Enter username: ')

    user_login2 = input('Enter password: ')

    success = False

    for credential in credentials:

        if login.upper() == credential[0].upper() and user_login2 == credential[1]:

            the_info = credential

            break

    if len(the_info) > 0 :

        print(f'Log in successful.  Hello {the_info[0]}')

    else:

        print('username or password incorrect.')


print(f'User info: {the_info}')


查看完整回答
反對 回復(fù) 2023-10-25
  • 2 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號