Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I write this code in python:

class Jam():

def __init__(self,a,b):

    self.a=a

    self.b=b      

def majmoo(self):

    return self.a+ self.b

numbers= Jam(10,55)

print(numbers.majmoo())

But it doesn't run and give this error:

NameError: name 'Jam' is not defined

I don't know why it gives this error I defined Jam() in the first line but It says it is not defined. How should I fix this?

1 Answer

0 votes
by (36.8k points)
edited by

Indentation problem. You did not indent the code inside the class. It should be like this:

class Jam():

    def __init__(self,a,b):

        self.a=a

        self.b=b      

    def majmoo(self):

        return self.a+ self.b

numbers= Jam(10,55)

print(numbers.majmoo())

 Learn Data Science with Python to improve your technical knowledge.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...