How to fix unexpected EOF while parsing in python 3.6?

*爱你&永不变心* 提交于 2019-12-23 05:26:43

问题


Im getting the EOF at the end of the program when i try to run it. i dont really know how to fix it. at first i was getting "if" as an invalid syntax but i think i was able to fix that. thanks for the help

while 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:


You're missing a except to match try.

Note that there are other issues with your code that will break it, even once you've added except. For example,

if choice == y: 
...

This should be 'y' instead of y. As it is, y is expected to be a variable, but you're looking to match on the user input 'y' or 'n'.

Also, if you want a string input, then:

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

will throw an error if you enter, say, 'y':

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

Try taking things one line at a time and making sure you understand what's supposed to happen at each point, and test it. Then put them together.



来源:https://stackoverflow.com/questions/46741791/how-to-fix-unexpected-eof-while-parsing-in-python-3-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!