Why do I get a SyntaxError when defining my class?

I am having a problem with the compiler with this exercise. The very first step gives me the error: “SyntaxError: unexpected EOF while parsing” with the code:

class Rules:

I checked and its the exact same as the solution given by codecademy (not much difficulty in this very first step…)

Any ideas on why?
THanks!

i had the same problem.
i think the reason why is because just wrighting the class is not the right proper syntaxt.
an class alawys needs to be defined. if you want to define an empty class you should use.

class Rules:
pass

and then later when you continue the code you can get rid of pass that is how i did it

10 Likes

i dont understand why in the example is:
class Dog():
dog_time_dilation = 7

and in the excersise is:
class Rules:

with out (), whats the difference?, i was using parentesis, as class Rules(): and i ve got the error metioned : “SyntaxError: unexpected EOF while parsing”

1 Like

All the Python 3 documentation I’ve read does not include parens on class definitions, although Python 2 used to include class Foo(object) and both require parens on derived classes for obvious reasons.

class Rules:
    pass

We must include at least pass for the syntax to be complete at this stage. Just a signature line is not enough and will raise a syntax error. The Shell will not let us return to the command prompt if we haven’t added the pass line.

Bottom line, until someone pipes in with better information, it doesn’t seem to make any difference. The convention is to not use them, so that would be the preferable option, as I see it.

10 Likes

thanks for the answer, i was confused on when to use them, :slight_smile:

i think the parentesis are the error, maybe the example of codeacademy is incorrect??

2 Likes

I cannot produce any errors with or without the parens on the definition line.Going forward it might be best to not use them.

2 Likes

@dnsold, Good eye and good question. Code Academy has updated the lesson and the parens is now absent in the class definition provided in the example.

image

2 Likes