Apply Operation

Apply Operation

Medium Python Functions 16 views
Explanation Complexity

Problem Statement

Read a b and op (ADD/SUB/MUL). Create function apply(a,b,op) and output result.

Input Format

One line: a b op.

Output Format

One integer result.

Example

10 5 SUB
5

Constraints

-10^18

Input / Output Format

Input Format
One line: a b op.
Output Format
One integer result.
Constraints
-10^18

Examples

Input:
10 5 SUB
Output:
5

Example Solution (Public)

Python
import sys
p=sys.stdin.read().strip().split()
if len(p)<3: sys.exit(0)
a=int(p[0]); b=int(p[1]); op=p[2]
def apply(x,y,o):
  if o=='ADD':
    return x+y
  if o=='SUB':
    return x-y
  return x*y
sys.stdout.write(str(apply(a,b,op)))

Official Solution Code

import sys
p=sys.stdin.read().strip().split()
if len(p)<3: sys.exit(0)
a=int(p[0]); b=int(p[1]); op=p[2]
def apply(x,y,o):
  if o=='ADD':
    return x+y
  if o=='SUB':
    return x-y
  return x*y
sys.stdout.write(str(apply(a,b,op)))
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.