+ 1
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))
8 odpowiedzi
+ 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))
+ 2
Thanks!
+ 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())
+ 1
Abs Sh chill, ok. I’m new at this
+ 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))
+ 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))
+ 1
This work perfectly ✍🏻🙏🏻
# your code goes here
class Shape:
def __init__(self, width, height):
self.width = width
Self.height = height
@staticmethod
def area(w, h):
return h * w
w = int(input())
h = int(input())
print(Shape.area(w, h))
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))