calculatrice python coding code example
Example 1: basic calculator in python
print("My Personal Python calculator")
num1 = int(input('Enter the first number: '))
num2 = int(input('Enter the second number: '))
opr = input('Enter the type of operation you want to perform between your chosen two numbers: ')
if opr=='+':
ans = num1 + num2
print(f'Your final answer is {ans}')
elif opr == '- ':
ans = num1 - num2
print(f'Your final answer is {ans}')
elif opr=='*':
ans = num1 * num2;
print(f'Your final answer is {ans}')
elif opr=='/':
ans = num1 / num2
print(f'Your final answer is {ans}')
else:
print('Invalid Entry!!!')
Example 2: Calculator in python
num1 = input("Enter a Number : ")
num2 = input("Enter a Number : ")
result = (num1 * num2)
print(result)
Example 3: python calculator
print('Calculator')
input_1 = input('First Number? ')
input_2 = input('Second Number? ')
try:
print(f'{input_1} + {input_2} is {float(input_1) + float(input_2)}')
print(f'{input_1} - {input_2} is {float(input_1) - float(input_2)}')
print(f'{input_1} X {input_2} is {float(input_1) * float(input_2)}')
print(f'{input_1} / {input_2} is {float(input_1) // float(input_2)}')
except Exception as e:
print(f'ERROR: {e}')
Example 4: python calculator
print("Choose operator (+,-,*,/):")
mode = input()
print("Choose first int:")
x = int(input())
print("Choose second int:")
y = int(input())
print("Your result:")
if mode == "+":
print(x+y)
elif mode == "-":
print(x-y)
elif mode == "*":
print(x*y)
elif mode == "/":
print(x/y)