info_outline

Solutions will be available when this assignment is resolved, or after a few failing attempts.

Shape Areas

Complete the given shape classes to compute the correct area for all of them:

Circles

Are created by passing radius in the constructor. The area of a circle is equals to πr^2. That's 3.14 * radius * radius (we round pi to 3.14).

Rectangles

They're created by passing height and width and area is equals to height * width.

Squares

Squares are created by passing the side measure of the square and the area is side * side .

IMPORTANT Squares are subclasses of Rectangles. The Square class should NOT implement the area method, only the __init__ method.

Examples:

c = Circle(radius=10)
c.area()  # 314.0 (3.14 * 10 * 10)

s = Square(side=4)
s.area()  # 16 (4 * 4)

r = Rectangle(height=4, width=3)
r.area()  # 12 (4 * 3)

Test Cases

test square - Run Test

def test_square():
    s = Square(side=4)
    assert s.area() == 16

test circle - Run Test

def test_circle():
    c = Circle(radius=10)
    assert c.area() == 314.0

test rectangle - Run Test

def test_rectangle():
    r = Rectangle(height=4, width=3)
    assert r.area() == 12
class Shape(object): def area(self): raise NotImplementedError() class Circle(Shape): pass class Rectangle(Shape): pass class Square(Rectangle): # Only __init__ method pass