I created this line of code today which determines whether a number divides evenly
if (numerator / denominator * denominator) == numerator:
print "Divides evenly!"
else:
print "Doesn't divide evenly."
Yet I ran into an issue when dividing by 0 as I still wanted it to tell me whether it would divide even if the denominator was 0 by looking at the numerator and seeing if it was even or odd. I came up with this:
if denominator != 0 and (numerator / denominator * denominator) ==
numerator:
print "Divides evenly!"
elif denominator == 0 and numerator % 2 == 0:
print "Divides evenly!"
else:
print "Doesn't divide evenly."
Is there any way to shorten this? Also, is there any way to not have to add the new 'elif' statement?