Answer to Question #235071 in Python for kaavya

Question #235071

Simple Calculator - 2

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.



1
Expert's answer
2021-09-11T01:30:06-0400
fields = input().split()


num1 = int(fields[0].strip())
num2 = int(fields[2].strip())
operator = fields[1].strip()


if operator == "+":
    print((num1 + num2))


elif operator == "-":
    print((num1 - num2))


elif operator == "*":
    print((num1 * num2))


elif operator == "/":
    print((num1 / num2))


elif operator == "%":
    print((num1 % num2))





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS