DEV Community

Mashad-pixel
Mashad-pixel

Posted on

calculator for beginner

num1 = float(input("enter a number :"))
symb = input("enter (+,-,*,/) :")
num2 = float(input("enter a number :"))

if symb == "+":
print("Answer =",num1+num2)
elif symb == "-":
print("Answer =",num1-num2)
elif symb == "*":
print("Answer =",num1*num2)
elif symb == "/":
if num2 != 0: #not to get an infinite loop as anything divided by zero is not defined
print("Answer =",num1/num2)
else:
print("Not defined as the num1 is divided by zero")
else:
print("invalid symb")

print()
print("Calculate anything else, I'm there for you")

Top comments (0)