make a simple calculator in python code example
Example 1: Calculator in python
num1 = input("Enter a Number : ")
num2 = input("Enter a Number : ")
result = (num1 * num2)
print(result)
Example 2: python calculator
try:
num1 = float(input("Please Enter The first number: "))
operator = input("Please choose the operator (+) for addition, (-) for subtraction, (*) for multiplication"
"(/) for division , (%) for remainder: ")
num2 = float(input("Please Enter The second number: "))
if operator == '+':
result = num1 + num2
print("The result is: ", result)
elif operator == '-':
result = num1 - num2
print("The result is: ", result)
elif operator == '*':
result = num1 * num2
print("The result is: ", result)
elif operator == '/':
try:
if True:
result = num1 / num2
print(result)
except ZeroDivisionError as err:
print(err, " oops! zero division occur ")
elif operator == '%':
if operator == '%':
result = num1 % num2
print("The result is: ", result)
else:
raise TypeError
except ValueError:
print("wrong value, suggest integer or decimal")
finally:
print("All Done")