Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在这段python代码中找不到我做错了什么_Python - Fatal编程技术网

我在这段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我应该把冒号放在哪里?是的,我刚刚意识到了这一点!呸!谢谢你的帮助。