[英]Could someone please help me with my Python code?
我剛剛開始學習 Python,希望能得到幫助。 我正在使用 MU 編輯器,但我無法通過第一個“if 語句”。 我點擊運行,然后輸入“Joe”,它一直在問我“你是誰?” 我在運行部分輸入此輸入是否正確? 還是應該在 REPL 或文本編輯器部分中使用 go? 謝謝您的幫助。
while True:
print('Who are you?')
name = input()
if name != 'Joe':
continue
print('Hello, Joe. What is the password? (It is a fish.)')
password = input()
if password == 'swordfish':
break
print('Access granted.')
因此,如果您使用的是 python3,請確保在代碼的第 1 行中有此內容。 #!/usr/bin/env python3
然后在運行文件時將其輸入到命令行中。 python3 "filename.py"
#!/usr/bin/env python3
name = input('Who are you?: ')
if name == "Joe":
print(f"Hello, {name}.")
password = input('What is the password? (It is a fish.)')
if password == 'swordfish':
print('Access granted.')
else:
print('Access denied.')
else:
print(f"Sorry {name}, I don't know you.")
我清理了您的代碼,因為不需要while True
語句。 如果您有任何問題,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.