當我嘗試運行這段代碼:我無法找到我做錯了什麼在這片Python代碼
它給我這個錯誤:
File "chatbot.py", line 4
answer = input(client_name + ": ")
^
但我不明白我做錯了什麼,誰能幫助我?
當我嘗試運行這段代碼:我無法找到我做錯了什麼在這片Python代碼
它給我這個錯誤:
File "chatbot.py", line 4
answer = input(client_name + ": ")
^
但我不明白我做錯了什麼,誰能幫助我?
縮進和缺少「:」在結束時,如果:
capitals = ["Lisbon", "Madrid", "Paris", "Berlin", "London",
"Reykjavik", "Dublin", "Stockolm", "Rome"]
client_name = "Me"
while True:
answer = input(client_name + ": ")
if answer == "What is the capital of Germany?":
print(capitals[3])
else:
print("I don't understand!")
謝謝!它的工作現在。 –
改變你的代碼:
capitals = ["Lisbon", "Madrid", "Paris", "Berlin", "London",
"Reykjavik", "Dublin", "Stockolm", "Rome"]
client_name = "Me"
while True:
answer = input(client_name + ": ")
if answer == "What is the capital of Germany?":
print(capitals[3])
else:
print("I don't understand!")
在python的縮進是代碼的一部分,你缺少「: 「if語句後
是的,我剛剛意識到這一點! Duhh!感謝您的幫助。 –
如果缺少冒號並且回答缺少縮進 –
我應該在哪裏放冒號? –