2024-10-02 14:18:41 发布
网友
我发现了这段代码,并尝试在python3上使用它,但它在geeks IDE上不起作用
list=input('racecar:') if (list==list[::-1]): print ("It is a palindrome") else: print("it is not palindrome")
我得到了:
list=input('racecar:') EOFError: EOF when reading a line
只有在input不可用或在调用期间突然关闭时,EOFError: EOF when reading line才可能在input调用期间发生
input
EOFError: EOF when reading line
既然您提到您是从geeks IDE使用它,我假设它没有针对用户输入重定向{}
geeks IDE
请尝试使用cmdpython <file>在终端上以交互方式运行代码
python <file>
您希望使用input接受用户输入,但可能没有将其提供给脚本。在
相反,尝试在尝试接受用户输入之前直接设置值。在
test_values = [ "non-palindrome", "123321", ] def palindrometest(s): return s == s[::-1] for value in test_values: if palindrometest(value): print("{} is a palindrome".format(value)) else: print("{} is not a palindrome".format(value))
一旦您完成了这项工作,请尝试在脚本中单独使用input来获得关于它如何工作的良好感觉。在
这是因为您可能正在使用python2.7。我刚刚在python3.6上测试了您的代码,它运行得很好(我确实将变量列表更改为lis)。在
只有在
input
不可用或在调用期间突然关闭时,EOFError: EOF when reading line
才可能在input
调用期间发生既然您提到您是从}
geeks IDE
使用它,我假设它没有针对用户输入重定向{请尝试使用cmd
python <file>
在终端上以交互方式运行代码您希望使用
input
接受用户输入,但可能没有将其提供给脚本。在相反,尝试在尝试接受用户输入之前直接设置值。在
一旦您完成了这项工作,请尝试在脚本中单独使用
^{pr2}$input
来获得关于它如何工作的良好感觉。在这是因为您可能正在使用python2.7。我刚刚在python3.6上测试了您的代码,它运行得很好(我确实将变量列表更改为lis)。在
相关问题 更多 >
编程相关推荐