SyntaxError: unexpected EOF while parsing in Python 3.8.2

Dung Do Tien Aug 23 2021 147

Hello Guys, I just studying Python 3.8.2 and I have an array as below and I want to know the length of each item.

wellknow_book = [['Clear code', 'Pro Python 1', 'Pro Python 2'],
            ['Asp.Net Pro', 'Css standard', 'Js in 36hs']]


for x in range(len(wellknow_book)):
    for y in range(len(wellknow_book[x])):
        print("This book name has length of:" + " " + str(len(wellknow_book[x][y]))

But when I run it I got an error SyntaxError: unexpected EOF while parsing.

File "main.py", line 8
  ^
SyntaxError: unexpected EOF while parsing

I still do not understand what is EOF, Anybody can explain to me?

Have 1 answer(s) found.
  • H

    Hà Minh Aug 23 2021

    EOF stands for End of File. This represents the last character in a Python program. Python reaches the end of a file before running every block of code if You forget to enclose code inside a special statement like a for loop, a while loop, or a function. 

    So you can see that your code is not valid and you forgot to enclose for print() method.

    wellknow_book = [['Clear code', 'Pro Python 1', 'Pro Python 2'],
                ['Asp.Net Pro', 'Css standard', 'Js in 36hs']]
    
    for x in range(len(wellknow_book)):
        for y in range(len(wellknow_book[x])):
            print("This book name has length of:" + " " + str(len(wellknow_book[x][y])))

    And it works for you!!

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close