python初学者,程序在python里总是报错,按着书上写的程序,咋回事呢?

写完polling_active = False:之后下一行不论写print语句)还是直接写for循环按回车之后都会报错。可以帮忙解答一下吗。
>>> responses = {}
>>> polling_active = True
>>> while polling_active:
...     name = input("\nWhat is your name?")
...     response = input("Which mountain would you like to climb someday?")
...     responses[name] = response
...     repeat = input("Would you like to let another person respond? (yes/no)")
...     if repeat == 'no':
...         polling_active = False
... for name, response in responses.items():
  File "", line 8
    for name, response in responses.items():
    ^^^
SyntaxError: invalid syntax

如果不写 if循环后面的代码程序就会运行但是想要达到的显示投票结果的效果就无法实现。
改缩进和拼写都没用
可以告诉我这是咋回事吗

不建议直接使用交互模式 来写这样的代码, 使用其他工具来书写吧,比如, idle, vscode 或者 pycharm 来书写
你的问题是 while 循环结束了,应该 再回车一次表示结束,之后,再写 for 循环,但如果你回车之后,就会直接执行 while 循环的代码, 执行完成后才能再写 for 循环, 见下图:

img