₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,001 members, 8,419,875 topics. Date: Thursday, 04 June 2026 at 05:54 AM

Toggle theme

Python Programming Question - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPython 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())
1 Reply

Why Is Python Programming So Hard To UnderstandCommon good python programming practices you should knowSomebody Should Help Me Answer This Programming Question234

ACSGPT: Applied Chess Science Generative Pre-trained Transformers - By ACS-Web-XSnapdragonLooking For Voiceover Actor