Answer to Question #261580 in Python for Mikee

Question #261580

5. Operation: Operation

by CodeChum Admin

You have been cordially invited to partake in Operation: Operation. Your mission, should you choose to accept it, is to take the two numbers and the operator given then perform the operation successfully.


Instructions:

  1. Input one number (integer or decimal), an operator (+, -, *, /), and another number (integer or decimal).
  2. Print the result of the operation between the two numbers, up to 2 decimal places.

Instructions

  1. Input one number (integer or decimal), an operator (+, -, *, /), and another number.
  2. Print the result of the operation between the two numbers, up to 2 decimal places.

Input

The first line contains the first number.

The second line contains the operator.

The third line contains the second number.

5
+
0.70

Output

A line containing a decimal/float containing two decimal places.


5.70
1
Expert's answer
2021-11-09T00:24:41-0500
x, operator, y = float(input()), input(), float(input())
if operator == '+':
    print(round(x + y, 2))
elif operator == '-':
    print(round(x - y, 2))
elif operator == '*':
    print(round(x * y, 2))
elif operator == '/' and y != 0:
    print(round(x / y, 2))
else:
    print('Wrong input!')

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
New on Blog
APPROVED BY CLIENTS