Header Ads

Responsive Ads Here

Question/Solution - 3

Question


Make a Simple calculator which will calculate two numbers and ask the numbers and operator from the user.




Answer



num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
oper = input("Enter the operator: ")


if oper == "+":
    print(f"The answer is {num1 + num2}")
elif oper == "-":
    print(f"The answer is {num1 - num2}")
elif oper == "*":
    print(f"The answer is {num1 * num2}")
elif oper == "/":
    print(f"The answer is {num1 / num2}")
elif oper == "%":
    print(f"The answer is {num1 % num2}")
else:
    print("Invalid input")

Powered by Blogger.