python calculator code copy and paste 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: how to make a python calculator
#Calculator
import time
def add():
n1 = input('Enter a number: ')
n2 = input('Enter another number: ')
time.sleep(1)
print(int(n1)+int(n2))
def multiply():
n1 = input('Enter a number: ')
n2 = input('Enter another number: ')
time.sleep(1)
print(int(n1)*int(n2))
def divide():
n1 = input('Enter a number: ')
n2 = input('Enter another number: ')
time.sleep(1)
print(int(n1)int(n2))
def subtract():
n1 = input('Enter a number: ')
n2 = input('Enter another number: ')
time.sleep(1)
print(int(n1)-int(n2))
run = True
while run:
ans = input('Select an opreation: ')
if(ans=='Addition'):
add()
if(ans=='Divide'):
divide()
if(ans=='Multiply'):
multiply()
if(ans=='Subtract'):
subtract()
Example 3: calculator code
x = input("first number")
y = input("second number")
z = input("do you want to multiply, minus, divide or add? (x,-,/,+)")
y = int(y)
x = int(x)
if z == "+":
print (x + y)
if z == "/":
print (x / y)
if z == "x":
print (x * y)
if z == "-":
print (x - y)
else:
print("use x,-,/ or + next time!")
Example 4: calculator in python
#Calculator in python
#No modules required
qus = input('')
if(qus=='ADDITON'):
no1 = int(input())
no2 = int(input())
print(no1+no2)
if(qus=='MULTIPLICATION'):
no1 = int(input())
no2 = int(input())
print(no1*no2)
if(qus=='DIVISION'):
no1 = int(input())
no2 = int(input())
print(no1/no2)
if(qus=='SUBTRACTION'):
no1 = int(input())
no2 = int(input())
print(no1-no2)