代码之家  ›  专栏  ›  技术社区  ›  Aaron

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

  •  0
  • Aaron  · 技术社区  · 9 年前

    当我尝试运行它时,我在程序结束时得到EOF。我真的不知道如何修复它。起初,我把“if”作为无效语法,但我认为我能够修复它。谢谢你的帮助

    虽然为True:

    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")  
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   andrew_reece    9 年前

    你错过了一个 except 匹配 try .

    请注意,代码中还有其他问题会破坏它,即使您添加了 除了

    if choice == y: 
    ...
    

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

    此外,如果需要字符串输入,则:

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

    “是” :

    invalid literal for int() with base 10: 'y'
    

    试着一次只做一行,确保你理解每一点应该发生什么,并进行测试。然后把它们放在一起。