Registry Synced

Jan 2026 - Python - Week 10 - GrPA 3

775 words
4 min read

GrPA 3

Course: Jan 2026 - Python
GrPA 3
Submission deadline has passed for this assignment
Due Apr 22, 2026 at 11:59 PM IST
Instructions
Use "Test Run" to verify your code with public test cases.
Press "Submit" to have your assignment evaluated.
You can submit your assignment multiple times up until the deadline.
Make sure to submit your final code by the deadline to receive your score.
Summary
100 out of100
Score
Public Tests
2/2 Passed
Submitted on Apr 22, 2026 at 7:17 PM IST
Private Tests
5/5 Passed
Submitted on Apr 22, 2026 at 7:17 PM IST

A class named Shape is given to you as a part of the prefix code. Write a class named Square that is derived from Shape with the following specification:
Attributes
Only those attributes that are specific to the derived class are mentioned below. The rest have to be inherited from the base class.
side: int, side of the square
Methods
Only those methods that are specific to the derived class are mentioned below. The rest have to be inherited from the base class.
(1) __init__: accept side as an argument: (2) Call the constructor of the base class and set the name attribute to "Square" using it. (3) Assign side to the corresponding attribute of this class. (4) Call the methods compute_area and compute_perimeter within the constructor. (5) compute_area: compute the area of the square and assign it to the attribute area. (6) compute_perimeter: compute the perimeter of the square and assign it to the attribute perimeter.

(1) Each test case corresponds to one or more method calls. We will use S to denote the name of the object.
(2) You do not have to accept input from the user or print output to the console. You just have to define the class based on the specifications given in the question.

Public Tests ( 2/2 )

Case 1

Input:
text
public
Square(4)
Expected Output:
text
4

Square has an area of 16 and perimeter of 16
Actual Output:
text
4

Square has an area of 16 and perimeter of 16

Case 2

Input:
text
public
Square(5)
Expected Output:
text
5

Square has an area of 25 and perimeter of 20
Actual Output:
text
5

Square has an area of 25 and perimeter of 20

Private Tests ( 5/5 )

Case 1

Input:
text
private
Square(10)
Expected Output:
text
10

Square has an area of 100 and perimeter of 40

You have defined the class correctly.
Actual Output:
text
10

Square has an area of 100 and perimeter of 40

You have defined the class correctly.

Case 2

Input:
text
private
Square(14)
Expected Output:
text
14

Square has an area of 196 and perimeter of 56

You have defined the class correctly.
Actual Output:
text
14

Square has an area of 196 and perimeter of 56

You have defined the class correctly.

Case 3

Input:
text
private
Square(1)
Expected Output:
text
1

Square has an area of 1 and perimeter of 4

You have defined the class correctly.
Actual Output:
text
1

Square has an area of 1 and perimeter of 4

You have defined the class correctly.

Case 4

Input:
text
private
Square(3)
Expected Output:
text
3

Square has an area of 9 and perimeter of 12

You have defined the class correctly.
Actual Output:
text
3

Square has an area of 9 and perimeter of 12

You have defined the class correctly.

Case 5

Input:
text
private
Square(15)
Expected Output:
text
15

Square has an area of 225 and perimeter of 60

You have defined the class correctly.
Actual Output:
text
15

Square has an area of 225 and perimeter of 60

You have defined the class correctly.

💻 IITM Official Solution

python
class Shape:
    def __init__(self, name):
        self.name = name
        self.area = None
        self.perimeter = None

    def display(self):
        print(f'{self.name} has an area of {self.area} and perimeter of {self.perimeter}')
class Square(Shape):
    def __init__(self, side):
        super().__init__('Square')
        self.side = side
        self.compute_area()
        self.compute_perimeter()

    def compute_area(self):
        self.area = self.side ** 2

    def compute_perimeter(self):
        self.perimeter = 4 * self.side


💻 My Submitted Code

python
class Shape:
    def __init__(self, name):
        self.name = name
        self.area = None
        self.perimeter = None

    def display(self):
        print(f'{self.name} has an area of {self.area} and perimeter of {self.perimeter}')

class Square(Shape):
    def __init__(self, side):
        super().__init__("Square")
        self.side = side
        self.compute_area()
        self.compute_perimeter()

    def compute_area(self):
        self.area = self.side ** 2

    def compute_perimeter(self):
        self.perimeter = 4 * self.side

Document Outline
Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.