Codey and Symbol

https://www.hackerrank.com/contests/codenection-2024-final-round-open-category/challenges/cn24-4/problem

Question

Codey was working on an equation but accidentally spilled water on its notes, blurring one of the symbols. Now, it can’t tell the correct relationship between the two sides of its equation.

The equation is given as:

a−(bc)?(de)−fa - (\frac{b}{c}) ? (\frac{d}{e}) - f

Help Codey find the relationship ?.

Print > if the left side is bigger, < if the right side is bigger, otherwise =.

Input Format

The first line contains 6 values, a,b,c,d,e,fa,b,c,d,e,f.

Constraints

0≤a,b,c,d,e,f≤1050 \le a, b, c, d, e, f \le 10^5
c,e≠0c, e \ne 0

Output Format

Print a single character:

  • >>, if left side is larger.

  • <<, if left side is smaller.

  • ==, if both sides are equal.

Sample Inputs:

Input

5 6 2 8 4 1

Output

>

Explanation

Left Side: 5−(62)=25 - (\frac{6}{2}) = 2

Right Side: (84)−1=1(\frac{8}{4}) - 1 = 1

2>12>1, therefore output >.


Solution - Rounding Trap

This question is more like testing if you know programming rounding issues.

In some reason, when you divide a value, the number would get different when it rounds too many significant values, which is in default. (which we called, float rounding error)

Therefore, when comparing, don't forget to round to 4 values or fewer, so that the comparison will be correct.

Here's the code:

a, b, c, d, e, f = map(int, input().strip().split())
lhs = a - (b / c)
rhs = (d / e) - f

if round(lhs, 4) > round(rhs, 4):
    print(">")
elif round(rhs, 4) > round(lhs, 4):
    print("<")
else:
    print("=")

Last updated