在 python 3.6 中解析时如何修复意外的 EOF?

How to fix unexpected EOF while parsing in python 3.6?

当我尝试 运行 时,我在程序结束时得到了 EOF。我真的不知道如何解决它。起初我得到 "if" 作为无效语法,但我想我能够解决这个问题。感谢您的帮助

虽然正确:

try: 

    print("Do you want to enter a number?")  
    print("y - yes")  
    print("n - no")  
    choice = int(input("Enter here: "))  
    if choice == y:  
        print("")  
        count = number

    for indice in range(1,number + 1, 1):  
        print(number + indice)  
        print("")  
        print("All done")  

您缺少匹配 tryexcept

请注意,即使您添加了 except,您的代码还有其他问题会破坏它。例如,

if choice == y: 
...

这应该是 'y' 而不是 y。实际上,y 应该是一个变量,但您希望匹配用户输入 'y''n'.

另外,如果你想要一个字符串输入,那么:

choice = int(input("Enter here: "))

如果您输入 'y':

将引发错误
invalid literal for int() with base 10: 'y'

尝试一次一行地处理事情,并确保您了解每一点应该发生什么,然后进行测试。然后把它们放在一起。