-2
class Area(object):
    def __init__(self, base, height):
        self.base = base
        self.height = height

    def calculation(self):
        return(self.base * self.height)

area = Area(15, 2)
print(Area.calculation())
TheEagle
  • 5,808
  • 3
  • 11
  • 39

2 Answers2

0

The Area in your print() is capitalized, while your variable area is not. That means that you are calling the Area Object instead of the variable.
This should work :

class Area(object):
    def __init__(self, base, height):
        self.base = base
        self.height = height

    def calculation(self):
        return(self.base * self.height)

area = Area(15, 2)
print(area.calculation())
Nathn
  • 418
  • 5
  • 17
0

You are calling the class object's calculation method (Area.calculation), instead of calling the calculation method of the Area instance (area.calculation). This works:

class Area(object):
    def __init__(self, base, height):
        self.base = base
        self.height = height

    def calculation(self):
        return self.base * self.height

area = Area(15, 2)
print(area.calculation())

Note the removed parentheses around the return argument - they are unnecessary as return is a keyword, not a function.

TheEagle
  • 5,808
  • 3
  • 11
  • 39