If I understand your question correctly, you just need to know how to best handle this comparison when some of the comparisons could be invalid. The pattern I normally see (and use) is to check for edge conditions (if they could be quite common) and handle them. If no edge conditions exist, you can move on to the standard process.
In this particular instance, you have one edge case defined: when one of your denominators is zero. So check whether any of int1
, int2
, or int3
is zero, and do something appropriate if so. If none of them are, you can continue with your ratio comparison.
if not (int1 and int2 and int3):
do_something_with_zero_values()
elif (int4/int3) == (int3/int2) == (int2/int1): # This is now a safe operation
do_something()
Of course, you could also use exception handling to deal with your edge cases. Prescriptively, you generally want to use exceptions only in "exceptional" circumstances, so if zero really is a legitimate value for these variables, I would recommend against conceptualizing it as an exception. See this question for more on that discussion.