Skip to main content

Write a program to implement the constructor.

· One min read
Kaustubh Kulkarni
file.py
import operator
from operator import eq, add, sub,mul
class calculator:
first, second = 0, 0
def __init__(self, f, s):
self.first = f
self.second = s
def calculate(self):
print("Answer is ",self.first+self.second)
n1=int(input("Enter No one : "))
n2=int(input("Enter No two : "))
obj = calculator(n1,n2)
obj.calculate()

Output:

Output

Enter No one : 4
Enter No two : 5
Answer is 9