Python Programming Question - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Python Programming Question (290 Views)
1 Reply
| Python Programming Question by jackaustin631(op): 10:20am On Feb 06, 2023 |
I'm new to programming and I'm trying to write a python program to help me with a problem that I am facing and I got stuck at trying to solve a problem similar to the one below. I recreated the error using a mock example. import numpy as np class test: def __init__(self, length, width): self.length = length self.width = width def area(self): self.length = length self.width = width area = self.length * self.width return area def area_2(self): return np.square(test.area()) rect = test(9,9) When I run rect.area_2() I get the following error: TypeError: area() missing 1 required positional argument: 'self' why doesn't this work? |
| Re: Python Programming Question by codemarshal08(m): 1:37pm On Feb 06, 2023 |
# this line is the cause of the error. return np.square(test.area()) I assume you are trying to call the area method from area_2 method. Fix: use the keyword self instead of the class name : return np.square(self.area()) |
Why Is Python Programming So Hard To Understand • Common good python programming practices you should know • Somebody Should Help Me Answer This Programming Question • 2 • 3 • 4
ACSGPT: Applied Chess Science Generative Pre-trained Transformers - By ACS-Web-X • Snapdragon • Looking For Voiceover Actor