原始输入多行字符串时出现python运行时错误

hem*_*mc4 2 python input

我想读多行输入.输入格式是第一行包含int为no.行后跟字符串行.我试过了

while True:
    line = (raw_input().strip())
    if not line: break

    elif line.isdigit(): continue

    else:
        print line
Run Code Online (Sandbox Code Playgroud)

它打印字符串行但显示运行时错误消息

Traceback (most recent call last):
  File "prog.py", line 2, in <module>
    line = (raw_input().strip())
EOFError: EOF when reading a line
Run Code Online (Sandbox Code Playgroud)

这是阅读输入的正确方法吗?
为什么运行时错误?
我是python的新手请帮助我

unu*_*tbu 6

如果使用EOF终止程序(Ctrl-d在Linux中,Ctrl-z在Windows中),则可能会收到EOFError .您可以通过以下方式捕获错误:

while True:
    try:
        line = (raw_input().strip())
    except EOFError:
        break
    if not line: break
Run Code Online (Sandbox Code Playgroud)