【问题标题】:How do I fix this EOF error如何修复此 EOF 错误
【发布时间】:2018-03-04 05:24:29
【问题描述】:

我的代码如下,附上错误截图的链接。它要我测试一个句子中的字符数

def get_num_of_characters(inputStr):
    return len(inputStr) 

def output_without_whitespace(inputStr):
    output=''
    for i in range(0,len(inputStr)):
        if(inputStr[i]==' ') or (inputStr[i]=='\t'):
    exit 
    else: 
        output+=inputStr[i]
return output

# if __name__=="__main__":

inputStr=input("Enter a sentence or phrase: \n")
print("You entered:",inputStr)
print("\nNumber of characters:",get_num_of_characters(inputStr))
print("String with no whitespace:",output_without_whitespace(inputStr))

输入一个句子或短语: 回溯(最近一次通话最后): 文件“zyLabsUnitTestRunner.py”,第 4 行,在 从 zyLabsUnitTest 导入 test_passed 文件“/home/runner/local/submission/unit_test_student_code/zyLabsUnitTest.py”,第 1 行,在 从主要导入 get_num_of_characters 文件“/home/runner/local/submission/unit_test_student_code/main.py”,第 15 行,在 inputStr=input("请输入一个句子或短语:\n") EOFError:读取一行时出现EOF

【问题讨论】:

  • 将回溯作为文本包含在代码中,而不是作为图像。
  • 改成raw_input不行吗?
  • 嘿凯文,它不起作用

标签: python-3.x


【解决方案1】:

这适用于我使用python-3.x。在2.x,我改了:

inputStr=input("Enter a sentence or phrase: \n")

收件人:

inputStr=raw_input("Enter a sentence or phrase: \n")

请参阅this answer 了解两者之间的更深入解释。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 2020-02-22
    • 2014-03-01
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多