Write a program to create a menu-driven calculator that performs basic arithmetic operations (+, -, *, /, and %).Input
The input will be a single line containing two integers and operator(+, -, *, /, and %) similar to 3 + 5.Output
If the given operator is "+", print the sum of two numbers.
If the given operator is "-", print the result of the subtraction of the two numbers.
If the given operator is "*", print the multiplication of the two numbers.
If the given operator is "/", print the result of the division of the two numbers.
If the given operator is "%", print the result of the modulus operation of the two numbers.Explanation
For example, if the given operator is "+" and the two numbers are 3 and 5. As it is an addition operator, your code should print the sum of the given two numbers (3 + 5), which is 8.
Similarly, if the given operator is "*" and the two numbers are 2 and 5.
As it is a multiplication operator, your code should print the result of the multiplication of the given two numbers (2 * 5), which is 10.
Similarly, if the given operator is "-" and the two numbers are 10 and 9.
As it is a subtraction operator, your code should print the result of the subtraction of the given two numbers (10 - 9), which is 1.
Similarly, if the given operator is "%" and the two numbers are 20 and 10.
As it is a Modulus operator, your code should print the result of the remainder of the given two numbers (20 % 10), which is 0.
num1 = int(input("Enter a Number: "))
num2 = int(input("Enter another Number: "))
operator = str(input("Enter the Operation you want: "))
if operator == "+":
print("Result is:" , (num1 + num2))
elif operator == "-":
print("Result is:" , (num1 - num2))
elif operator == "*":
print("Result is:" , (num1 * num2))
elif operator == "/":
print("Result is:" , (num1 / num2))
elif operator == "%":
print("Result is:" , (num1 % num2))
Comments
Dear chandra the code works well
for this code line 1 showing error
Leave a comment