我正在Hackerrank上处理一个非常基本的问题。
输入格式:
第一行包含整数N。
第二行包含字符串S.
输出格式:
第一行应包含N x 2。
第二行应包含相同的字符串S.
样本测试用例
5
helloworld
我的代码是:(在PYTHON 3上(
n=int(input())
s=input()
print(2*n)
print(s)
我收到错误:
Execution failed.
EOFError : EOF when reading a line
Stack Trace:
Traceback (most recent call last):
File "/tmp/143981299/user_code.py", line 1, in <module>
N = int(input())
EOFError: EOF when reading a line
我尝试了很多次这种方法来获取输入,这是我第一次出现这种错误。谁能解释一下原因吗?
使用try/except块来处理错误
while True:
try:
n=int(input())
s=input()
print(2*n)
print(s)
except:
break