Safe Modulo
Python
Easy
2 views
Problem Description
Read two integers a and b. Output a%b. If b is 0 output DIVIDE BY ZERO. If input is invalid, output ERROR.
Input Format
One line: a b.
Output Format
One line answer.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if len(p)<2:
sys.stdout.write('ERROR')
else:
try:
a=int(p[0]); b=int(p[1])
if b==0:
sys.stdout.write('DIVIDE BY ZERO')
else:
sys.stdout.write(str(a%b))
except Exception:
sys.stdout.write('ERROR')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!