What am I missing here? 24.2 Define the Methods (Intermediate Python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What am I missing here? 24.2 Define the Methods (Intermediate Python)

Static Methods The given code takes 2 numbers as input and calls the static area() method of the Shape class, to output the area of the shape, which is equal to the height multiplied by the width. To make the code work, you need to define the Shape class, and the static area() method, which should return the multiplication of its two arguments. Use the @staticmethod decorator to define a static method. #your code goes here Class Shape: def __init__(self, width, height): self.width = width self.height = height @staticmethod def validate_area(self): return self.width * self.height w = int(input()) h = int(input()) print(Shape.area(w, h))

26th Aug 2021, 3:50 PM
Cory Peitsch
Cory Peitsch - avatar
8 Answers
+ 10
class Shape: def __init__(self, width, height): self.width = width self.height = height @staticmethod def area(self): return self.width * self.height w = int(input()) h = int(input()) s = Shape(w, h) print(Shape.area(s))
26th Aug 2021, 4:37 PM
SoloProg
SoloProg - avatar
+ 2
Thanks!
26th Aug 2021, 5:06 PM
Cory Peitsch
Cory Peitsch - avatar
+ 2
I tried the above methods but they’re not working, but this works: #your code goes here class Shape: def __init__(self, width, height): self.width = width self.height = height @staticmethod def area(): return h * w w = int(input()) h = int(input()) print(Shape.area())
26th Sep 2021, 4:23 PM
Bozz
Bozz - avatar
+ 1
Abs Sh chill, ok. I’m new at this
26th Aug 2021, 7:07 PM
Cory Peitsch
Cory Peitsch - avatar
+ 1
This works for me. class Shape: def __init__(self, width, height): self.width = width self.height = height @staticmethod def area(self, other): return h * w w = int(input()) h = int(input()) print(Shape.area(w, h))
11th Jan 2022, 10:48 PM
Andrew Sharon
+ 1
#your code goes here  IT WORKS class Shape: def __init__(self, width, height): self.width = width self.height = height @staticmethod def area(self): return self.width * self.height w = int(input()) h = int(input()) ob = Shape(w, h) print(Shape.area(ob))
14th Feb 2022, 9:44 PM
Liria
Liria - avatar
0
w = int(input()) h = int(input()) class Shape: def __init__(self,width,lengh): self.width=width self.lengh=lengh @staticmethod def area(w,h): return w * h print(Shape.area(w, h))
14th Dec 2023, 11:55 AM
vahid kamrani
vahid kamrani - avatar
- 2
static method with self argument?!! do you not know what staticmethod is. you broke the complete definition
26th Aug 2021, 5:33 PM
Abs Sh
Abs Sh - avatar