Basic Calculator
Python
Easy
4 views
Problem Description
Input has two integers a and b and an operator op are provided (+, -, *, /, %). For / do integer floor division like Python //. Output the result.
Input Format
One line: a b op.
Output Format
One integer result.
Official Solution
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]
if op=='+': ans=a+b
elif op=='-': ans=a-b
elif op=='*': ans=a*b
elif op=='/': ans=a//b
else: ans=a%b
sys.stdout.write(str(ans))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!