Registry Synced

Jan 2026 - Python - Week 10 - GrPA 1

579 words
3 min read

GrPA 1

Course: Jan 2026 - Python
GrPA 1
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:10 PM IST
Private Tests
5/5 Passed
Submitted on Apr 22, 2026 at 7:10 PM IST

Create a class named Calculator that has the following specification:
Attributes
(1) a: int, we shall call this the first attribute
(2) b: int, we shall call this the second attribute
Methods
(1) __init__: accept two arguments a and b, assign them to the corresponding attributes (2) add: return the sum of the two attributes (3) multiply: return the product of the two attributes (4) subtract: subtract the second attribute from the first and return this value (5) quotient: return the quotient when the first attribute is divided by the second attribute (6) remainder: return the remainder when the first attribute is divided by the second

(1) Each test case corresponds to one or more method calls. We will use C 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
Calculator(3, 5)
C.add()
Expected Output:
text
8
Actual Output:
text
8

Case 2

Input:
text
public
Calculator(5, 10)
C.quotient()
Expected Output:
text
0
Actual Output:
text
0

Private Tests ( 5/5 )

Case 1

Input:
text
private
Calculator(3, 9)
C.multiply()
Expected Output:
text
27

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

You have defined the class correctly.

Case 2

Input:
text
private
Calculator(5, 15)
C.subtract()
Expected Output:
text
-10

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

You have defined the class correctly.

Case 3

Input:
text
private
Calculator(19, 3)
C.remainder()
Expected Output:
text
1

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

You have defined the class correctly.

Case 4

Input:
text
private
Calculator(15, 5)
C.quotient()
Expected Output:
text
3

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

You have defined the class correctly.

Case 5

Input:
text
private
Calculator(10, 50)
C.add()
Expected Output:
text
60

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

You have defined the class correctly.

💻 IITM Official Solution

python
class Calculator:
    def __init__(self, a, b):
        self.a, self.b = a, b
    def add(self):
        return self.a + self.b
    def multiply(self):
        return self.a * self.b
    def subtract(self):
        return self.a - self.b
    def quotient(self):
        return self.a // self.b
    def remainder(self):
        return self.a % self.b


💻 My Submitted Code

python
class Calculator:
    def __init__(self, a, b):
        self.a = a
        self.b = b
    def add(self):
        return self.a + self.b
    def multiply(self):
        return self.a * self.b
    def subtract(self):
        return self.a - self.b
    def quotient(self):
        return self.a // self.b
    def remainder(self):
        return self.a % self.b

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.