Compare Floats with Epsilon
Python
Medium
3 views
Problem Description
Read two floats a and b. If |a-b| < 1e-9 output EQUAL. Else output GREATER if a>b else SMALLER.
Input Format
One line: a b.
Constraints
Input is valid floats.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
a=float(p[0]); b=float(p[1])
if abs(a-b)<1e-9:
sys.stdout.write('EQUAL')
elif a>b:
sys.stdout.write('GREATER')
else:
sys.stdout.write('SMALLER')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!