build a calculator using python code example

Example 1: simple python calculator

#Store number variables for the two numbers

num1 = input('Enter first number: ')
num2 = input('Enter second number: ')

#the sum of the two numbers variable
sum = float(num1) + float(num2)
sum2 = float(num1) - float(num2)
sum3 = float(num1) * float(num2)
sum4 = float(num1) / float(num2)

#what operator to use
choice = input('Enter an operator, + = addition, - = subtraction, * = multiplication and / = division: ')
#different sums based on the operators
if choice == '+':
  print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

  if choice == '-':
    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum2))

if choice == '*':
    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum3))

if choice == '/':
    print('The sum of {0} and {1} is {2}'.format(num1, num2, sum4))

Example 2: calculator in python

def mutiply (x):
    return 5*x
o = mutiply(10)
print(o)

Example 3: Calculator in python

num1 = input("Enter a Number : ")
num2 = input("Enter a Number : ")
result = (num1 * num2)
print(result)
# And then print out the result

Example 4: calculator python

#this is a fraction calculator
def fractions_regular(fractions):
    f1 = input(13,25)
    f1 = fractions.Fraction(f1)
    f2 = input(6,25)
    f2 = fractions.Fraction(f2)
    operation = input('what is your iperation?')
    if operation == '+':
        print('{} + {} = {}'.format(f1, f2, f1 + f2))
    if operation == "-":
        print('{} - {} = {}'.format(f1, f2, f1 - f2))
    if operation == "*":
        print('{} * {} = {}'.format(f1, f2, f1 * f2))
    if operation == "/":
        print('{} / {} = {}'.format(f1, f2, f1 / f2))