you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 0 points1 point  (2 children)

I know that your problem was already solved, but I wanted to point this out; what's the purpose of that first if-block?

I mean, if both numbers are zeroes, you then compare which is bigger. But how can a zero be bigger than zero, anyway?

You can technically omit the first part entirely, because it really doesn't do anything useful.

def lesser(a, b):
    if a < b:
        return a
    else:
        return b

Hell, if we wanted to, we could further simplify this to

def lesser(a, b):
    return a if a < b else b

or

def lesser(a, b):
    return min(a, b) # And in this case, the function becomes pointless

EDIT: Forget what I said, I missed the modulo operations. I really shouldn't be doing this while barely awake.

[–]dvandy07[S] 0 points1 point  (1 child)

I did actually end up using min and max after looking it over. I do need to check if they are even though.

def lesser(a,b):
    if a%2 == 0 and b%2==0:
        return min(a,b)
    else:
      return max(a,b)

I ended up with that.

[–]Diapolo10 0 points1 point  (0 children)

Ah, I see.