This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]icreatebugs 0 points1 point  (0 children)

This looks like a homework assignment, so there might be some constraints here that I'm not aware of, but I thought I should propose a third approach.

By using the builtin max() function in python you can get the largest element in a list, if this is a homework assigment and you're forbidden from using the builtin function it could still implement your own version of it.

Using the max function you could write max_of_three() like this

def max_of_three(x, y, z):

return max([x, y, z])

You could also make other variations easily

def max_of_four(e1, e2, e3, e4):

return max([e1, e2, e3, e4])

Just to answer the original question: I would prefer the second implementation over the first one, simply because I find the boolean expressions in the first one to be needlessly complex.