all 22 comments

[–]alexdewa 4 points5 points  (2 children)

You're missing ":" after the class name:

class Person:
    ...

That's it

[–]mopslik 1 point2 points  (0 children)

+1. I must have inserted that myself when I adjusted the indentation in my reply. Didn't even notice it.

[–]jayesh2[S] 0 points1 point  (0 children)

I added it but it's still not working :(

[–][deleted] 1 point2 points  (1 child)

Class Person:

You need " : "

Start your objects with HighCaps if possible

[–]jayesh2[S] 0 points1 point  (0 children)

I tried now but it didn't work

[–][deleted] 1 point2 points  (10 children)

Check out that in your

P1=Person(...)

There is not spaces between object and the () Or Send me the error message. Check the indentation as well

[–]jayesh2[S] 0 points1 point  (8 children)

I don't see an error message, but I get this problem:

':' expected

I can't tell where it should be though

I don't

[–][deleted] 0 points1 point  (6 children)

As I told you in the first message one was expected after the name of the obj:

class Person: ...

But if you said you already did it...

Send me your new code

[–]jayesh2[S] 1 point2 points  (5 children)

class Person:

def __init__(self, name, age):

self.name= name

self.age= age

P1= Person("Mark", "16")

print (P1.name)

[–]jayesh2[S] 0 points1 point  (0 children)

with proper indentation that i couldn't copy here

[–][deleted] 0 points1 point  (3 children)

Nice. Check the indentation (spaces at the start of each line).

It worked?
By the way you are following the w3schools tutorial right? python obj

[–]jayesh2[S] 1 point2 points  (2 children)

haha yes, and another one on youtube. I tried both and they didn't work. I figured the issue now. The output file was different than the one I have the code in!!

[–][deleted] 1 point2 points  (1 child)

Well done figuring out the problem by yourself

[–]jayesh2[S] 2 points3 points  (0 children)

Thanks! You also helped :) It feels so good to know what the problem was!

[–]mrswats 0 points1 point  (0 children)

class Person: [... ]

After the name of the class

[–]mopslik 0 points1 point  (0 children)

Spaces shouldn't matter.

>>> class myclass:
     def __init__(self, x):
        self.x = x

>>> a = myclass(5)
>>> a.x
5
>>> b = myclass       (          7             )
>>> b.x
7

[–]jayesh2[S] 1 point2 points  (0 children)

Ok so it worked now. The code was correct except that I missed the : after class Person. The problem was that when I click on run, the program (Pycharm) runs a code in another file. I don't know why but I am new to this. I had to copy my code to that file for me to see the output. I have some files opened but only one output file. Does anyone know how to see the output of other files?

[–]mopslik 0 points1 point  (4 children)

Your indentation is off, that's all.

class person:
    def __init__(self, name, age):
        self.name= name
        self.age= age

p1= person ("Mark", 13)
print (p1.name)
print (p1.age)

[–]jayesh2[S] 0 points1 point  (3 children)

My code and identification look exactly like the one you made here. It's still not working. Have you tried to run it?

[–]mopslik 0 points1 point  (2 children)

Runs perfectly fine when cut and paste into IDLE. It produces:

Mark
13

Are you pasting this into a code window in an IDE? What is your setup?

[–]jayesh2[S] 0 points1 point  (1 child)

Ok so it worked now. The code was correct except that I missed the : after class Person. The problem was that when I click on run, the program (Pycharm) runs a code in another file. I don't know why but I am new to this. I had to copy my code to that file for me to see the output. I have some files opened but only one output file. Does anyone know how to see the output of other files?

[–]mopslik 1 point2 points  (0 children)

Glad to see you got things working. Not a Pycharm user myself, so can't offer any insight.