Safe Integer Division

Safe Integer Division

Easy Python Error Handling 14 views
Explanation Complexity

Problem Statement

Read two integers a and b. Output a//b. If b is 0 output DIVIDE BY ZERO. If input is not valid, output ERROR.

Input Format

One line: a b.

Output Format

One line answer.

Example

10 2
5

Constraints

|a|,|b|

Input / Output Format

Input Format
One line: a b.
Output Format
One line answer.
Constraints
|a|,|b|

Examples

Input:
10 2
Output:
5

Example Solution (Public)

Python
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')

Official Solution Code

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')
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.