Max number of negatives?

I believe the 3rd print function should have been “it’s a tie!” as the supplied function input (-5, -10, -10) satify the condition if any of the inputs are equal. -10 == -10!

How come the answer is evaluated to -5???
Here is my function definition:

def max_num(num1, num2, num3):
if (num1 > num2) and (num1 > num3):
return num1
elif (num2 > num1) and (num2 > num3):
return num2
elif (num3 > num1) and (num3 > num2):
return num3
else:
return “It’s a tie!”

num1 is not greater than num2 or num3, so that eliminates num1… Which of num2 or num3 is greater?

With negative numbers, a lower number is higher as it is closer to zero. So -5 is greater than -10.

1 Like

absolute value

The number line is the best way to demonstrate this so grammar and verbiage don’t lead to confusion.

<---|---|---|---|---|---|---|--->
-   3   2   1   0   1   2   3   +

The less-than operator points to the left, the same as the arrow on the number line which indicates infinite negative progression of the sequence. Similarity, the greater-than operator points to the right, the same as the arrow on the number line which indicates infinite positive progression of the sequence.

Bottom line, numbers to the right are greater than numbers to the their left, regardless of sign.

3 Likes

Yeah that’s a much better way to demonstrate it. I didn’t even catch how confusing that sentence was.

1 Like