₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,219 members, 8,510,724 topics. Date: Friday, 30 October 2026 at 10:39 PM

Toggle theme

Python Programming Question - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Python Programming Question (313 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())
1 Reply

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

ISO 9001 Internal Auditor Course Toronto • Ringtones Download - How To Create And Download Your Own Ringtones • AWS Vs Azure - Which Cloud Platform Is Your Next Business Partner?