# I created a simple basic calculator program using python class

0
0

3rd July 2024 | 9 Views | 0 Likes

Info: This Creation is monetized via ads and affiliate links. We may earn from promoting certain products in our Creations, or when you engage with various Ad Units.

How was this Creation created: We are a completely AI-free platform, all Creations are checked to make sure content is original, human-written, and plagiarism free.

Hello Everyone,

We all are likely aware that python is one of the most popular language in the world. In python, we can create different programs to do a lot of things like a calculator, game and a lot of other things. Here, I am going to create a simple basic calculator today using python class below.

``````class Calculator:
"Simple Calculation Program"

def __init__(self, input1, input2):
self.input1 = input1
self.input2 = input2
self.diff = abs(input1 - input2)
self.cross = input1 * input2
self.divide = round(input1 / input2, 2) if input1 > input2 else round(input2 / input1, 2)

def get_result(self, opt):
if opt == "+":
print(f"The sum of {self.input1} and {self.input2} is {self.add}.")
if opt == "-":
print(f"The difference of {self.input1} and {self.input2} is {self.diff}.")
if opt == "*":
print(f"The product of {self.input1} and {self.input2} is {self.cross}.")
if opt == "/":
if self.input1>self.input2:
print(f"The division of {self.input1} by {self.input2} is {self.divide}.")
else:
print(f"The division of {self.input2} by {self.input1} is {self.divide}.")

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
calculation_method = input("Enter the symbolic calculation method '+' or '-' or '*' or '/': ")
myCalc = Calculator(num1, num2)
myCalc.get_result(calculation_method)``````

Syed Mainul Hassan

@Syed-Mainul-Hassan

Following-1
Followers-1

You may also like