[英]Getting EOF Error while giving inputs to code
I tried a problem from SPOJ called The next palindrome.我尝试了 SPOJ 的一个名为 The next palindrome 的问题。 The problem statement is given as
问题陈述如下
A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left.
一个正的 integer 如果在十进制系统中从左到右和从右到左读取时的表示相同,则称为回文。 For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output.
对于给定的不超过 1000000 位的正数 integer K,将大于 K 的最小回文的值写入 output。 Numbers are always displayed without leading zeros.
数字始终显示不带前导零。
Here is my code这是我的代码
def palindrome(n):
return True if n[::-1] == n else False
t = int(input())
for i in range(t):
li = []
n = input()
for j in range(int(n) + 1, 1000000 + 1):
if palindrome(str(j)) == True:
li.append(j)
print(li[0])
I tried giving an input like this我试着给出这样的输入
1
1000000
I am getting an error like this我收到这样的错误
Traceback (most recent call last):
File "./prog.py", line 7, in <module>
EOFError: EOF when reading a line
The error is caused because your input "n" makes both arguments same in the range function in this line "for j in range(int(n) + 1, 1000000 + 1)".该错误是因为您的输入“n”使 arguments 在这一行中的 function 范围内相同“for j in range(int(n) + 1, 1000000 + 1)”。 It looks like this range(1000001, 1000001) which return nothing.
看起来这个范围(1000001, 1000001)什么都不返回。 Use input of "n" smaller than 1000000. It will work.
使用小于 1000000 的“n”输入。它将起作用。
It return empty list when I use this code.当我使用此代码时,它返回空列表。
n = 1000000
print(list(range(int(n) +1, 1000000+1)))
That why there is no data in it.这就是为什么里面没有数据。 EOF error is caused when python doesn't read any data.
当 python 没有读取任何数据时会导致 EOF 错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.