python program for calculator code example
Example 1: basic calculator in python
#My Personal Python calculator
print("My Personal Python calculator")
#inputs
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
#opration req
opr = input('Enter the type of operation you want to perform between your chosen two numbers: ')
#calculation
if opr=='+':
ans = num1 + num2
# displaying the answer
print(f'Your final answer is {ans}')
elif opr == '- ':
ans = num1 - num2
# displaying the answer
print(f'Your final answer is {ans}')
elif opr=='*':
ans = num1 * num2;
# displaying the answer
print(f'Your final answer is {ans}')
elif opr=='/':
ans = num1 / num2
# displaying the answer
print(f'Your final answer is {ans}')
else:
print('Invalid Entry!!!')
Example 2: 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 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!")