python calculator codeing code example
Example 1: python calculator
num_one = int(input("Enter 1st number: "))
op = input("Enter operator: ")
num_two = int(input("Enter 2nd number: "))
if op == "+":
print(num_one + num_two)
elif op == "-":
print(num_one - num_two)
elif op == "*" or op == "x":
print(num_one * num_two)
elif op == "/":
print(num_one / num_two)
Example 2: how to make a calculator in python
class Calculator:
def addition(a,b):
return a + b
def subtraction(a,b):
if a<b:
return b - a
else:
return a - b
def multiplication(a,b):
return a * b
def division(a,b):
if a<b:
return b / a
else:
return a / b
<C:/Users/username>python
>>> from main import Calculator
>>> result = Calculator.[addition|subtraction|multiplication|division](anyNumber, anyNumber)
>>> print(result)