class Trapezoid:
    def __init__(self, h, a, b):
        self.h = h
        self.a = a
        self.b = b
    def getArea(self):
        return 0.5 (a + b) * h
small_trapezoid = Trapezoid(6, 3, 4)
print('The area of the trapezoid is', small_trapezoid.getArea())
            Asked
            
        
        
            Active
            
        
            Viewed 353 times
        
    -1
            
            
         
    
    
        Jay Will
        
- 1
- 1
- 
                    return 0.5 (self.a + self.b) * self.h – Chase Jun 27 '20 at 03:01
- 
                    When you're referencing class members, you need to use `self.a` and `self.b`. `a`, `b`, and `h` are scoped in self. – Alex Jun 27 '20 at 03:02
- 
                    `self.a`, not `a`. Who does `a` belong to? `self`. – Mateen Ulhaq Jun 27 '20 at 03:02
- 
                    If you are new to the language, at the very least you should check out the [official docs](https://docs.python.org/3/tutorial/classes.html) where this would have been revealed – juanpa.arrivillaga Jun 27 '20 at 03:03
- 
                    Welcome to stackoverflow, please read [this guide](https://stackoverflow.com/help/how-to-ask) on how to properly ask on this site. – vlizana Jun 27 '20 at 03:09
2 Answers
1
            
            
        That's right, it's not defined. You meant self.a, as well as the other two.
return 0.5 (self.a + self.b) * self.h
Though then you have another error: TypeError: 'float' object is not callable
 
    
    
        wjandrea
        
- 28,235
- 9
- 60
- 81
0
            
            
        So you are trying to access 'a', 'b' and 'h' values in the getArea method, you might want to change it to
    def getArea(self):
        return 0.5 (self.a + self.b) * self.h
 
    
    
        Kingsley Solomon
        
- 481
- 1
- 4
- 9