我在这段python代码中找不到我做错了什么
当我尝试运行这段代码时:我在这段python代码中找不到我做错了什么,python,Python,当我尝试运行这段代码时: 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])
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!")
它给了我这个错误:
File "chatbot.py", line 4
answer = input(client_name + ": ")
^
但我不明白我做错了什么,有人能帮我吗?缩进和缺失:在if的末尾:
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语句之后if missing冒号和answer missing indentation我应该把冒号放在哪里?是的,我刚刚意识到了这一点!呸!谢谢你的帮助。