Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Challenge 3: Implement a Calculator Class

Sumit Rawal answered on May 17, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers


Challenge 3: Implement a Calculator Class

0

Problem statement

Write a Python class called Calculator by completing the tasks below:

Task 1

Initializer

Implement an initializer to initialize the values of num1 and num2.

Properties

num1

num2

Task 2

Methods

add() is a method that returns the sum of num1 and num2.

subtract() is a method that returns the subtraction of num1 from num2.

multiply() is a method that returns the product of num1 and num2.

divide() is a method that returns the division of num2 by num1.

Input

Pass numbers (integers or floats) in the initializer.

Output

addition, subtraction, division, and multiplication

Sample input

obj = Calculator(10, 94);

obj.add()

obj.subtract()

obj.multiply()

obj.divide()

Sample output

104

84

940

9.4

Coding exercise

Design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so initially try to solve it on your own. If you get stuck, you can always refer to the solution provided in the next lesson. 

Popularity 1/10 Helpfulness 1/10 Language python
Source: Grepper
Link to this answer
Share Copy Link
Contributed on May 17 2023
Sumit Rawal
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.