为什么我的简单代码在spyder上运行良好,但在SPOJ的在线IDE上却运行不佳?

问题描述

这是我针对SPOJ的第一个初学者水平问题的代码: 从输入到输出重写少量数字。读完数字42后,停止处理输入。输入中的所有数字都是一位或两位数字的整数。 我的代码

b=[]
while True:
    n=int(input('Enter the number less than 100 : '))
    if(n>100):
        continue
    else:
        b.append(n)
        if n==42:
           break
for i in b:
    print(i)

但抛出错误

Runtime error #stdin #stdout #stderr 0.15s 23320KB
Traceback (most recent call last):
  File "./prog.py",line 4,in <module>
EOFError: EOF when reading a line

我希望我很清楚,请以一种友好的方式指出我的错误:)因为我是一个初学者,而且自学成才。 谢谢。

解决方法

尝试将tryexcept用于代码。

插入所有正在尝试的代码,然后除通过

try:
   b = []
   while True:
       n=int(input('Enter the number less than 100 : '))
       if(n>100):
           continue
       else:
           b.append(n)
           if n==42:
              break
   for i in b:
       print(i)

except:
   pass