# Help with if statement and number comparison

I see one error with my code. It prints entered numbers are equal, though c is not equal to a & b.

Not sure how to correct it without making it too complicated.

`Preformatted text`
#program to compare the entered three numbers

a = 7
b = 7
c = 3

if((a>b and a>c) and (a != b and a != c)):
print(a, " is the largest")
elif((b>a and b>c) and (b != a and b != c)):
print(b, " is the largest")
elif((c>a and c>b) and (c != a and c != b)):
print(c, " is the largest")
else:
print(“entered numbers are equal”)

(Please read the pinned thread and fix the code formatting, so that the code shows up properly. What you’re trying to do is simple enough that I can guess the indentation; but talking about code in general means we should see exactly how it’s indented - in case that’s part of the problem. Improperly formatted code can also mess up a lot of other details.)

The root problem is with the logical expectation, not with the programming. With your input, none of your numbers “is the largest” (because two of them are tied for largest), and also they are not all equal (because `c` is smaller than the other two). So it’s simply not possible to say the correct result, because the correct result isn’t any of the possibilities you tried to check. To fix it you would need to consider more options.

In order to “not make it too complicated”, we need to change the approach to how we do the checks. Try to study the built-in `max` function, which you can use to get the biggest number from the options. If you know that information, then you can check (and output) which of the numbers (it could be just one, two or all three of them) is equal to that maximum value. For example, you could make a list that stores the names (as strings) for which variables are equal to the maximum (by checking each variable and putting the appropriate names into the list), and then use a single `print` to show the names in the list.

More generally: if you want your values to have “names” that you actually use in your output, store somewhere else in your program, manipulate as text etc. - in other words, if you want to have actual strings that represent the names - then instead of making separate variables, you really want a dictionary. Then you can have those strings be the keys of the dictionary.

Change the message to `"Two of a, b and c are equal to the maximum value."`

Note, `a>b` implies `a!=b`. There’s a `>=` operator to include equality.

I’d maybe rewrite this as:

``````a = 7
b = 7
c = 3

l = [a,b,c]

max_ = max(l)
freq = l.count(max_)

if freq == 1:
print(f"The unique maximum value is: {max_}")
else:
print(f"The maximum value: {max_} occurs {freq} times in [a,b,c].")

``````