Neural Sync Active
Jan 2026 - Python - Week 10 - GrPA 3
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:
textpublic Square(4)
Expected Output:
text4 Square has an area of 16 and perimeter of 16
Actual Output:
text4 Square has an area of 16 and perimeter of 16
Case 2
Input:
textpublic Square(5)
Expected Output:
text5 Square has an area of 25 and perimeter of 20
Actual Output:
text5 Square has an area of 25 and perimeter of 20
Private Tests ( 5/5 )
Case 1
Input:
textprivate Square(10)
Expected Output:
text10 Square has an area of 100 and perimeter of 40 You have defined the class correctly.
Actual Output:
text10 Square has an area of 100 and perimeter of 40 You have defined the class correctly.
Case 2
Input:
textprivate Square(14)
Expected Output:
text14 Square has an area of 196 and perimeter of 56 You have defined the class correctly.
Actual Output:
text14 Square has an area of 196 and perimeter of 56 You have defined the class correctly.
Case 3
Input:
textprivate Square(1)
Expected Output:
text1 Square has an area of 1 and perimeter of 4 You have defined the class correctly.
Actual Output:
text1 Square has an area of 1 and perimeter of 4 You have defined the class correctly.
Case 4
Input:
textprivate Square(3)
Expected Output:
text3 Square has an area of 9 and perimeter of 12 You have defined the class correctly.
Actual Output:
text3 Square has an area of 9 and perimeter of 12 You have defined the class correctly.
Case 5
Input:
textprivate Square(15)
Expected Output:
text15 Square has an area of 225 and perimeter of 60 You have defined the class correctly.
Actual Output:
text15 Square has an area of 225 and perimeter of 60 You have defined the class correctly.
💻 IITM Official Solution
pythonclass 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
pythonclass 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