 # FAQ: Code Challenge: Control Flow - Max Number

Hoping someone can give me some give me some insights into difference between the Codeacademy solutions (on top) and my solution (on bottom). For some reason I think that , the codeacademy solutions won’t or shouldn’t return anything if the lowest 2 numbers are equal

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!”

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

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!”

This code works fine though I want to know if I change all of the elif statements in the code into if statement what will happen. Will it make any error? Or will the logic works the same as the current one?

Try it and see. From what we can tell everything should work the same owing that each branch exits the function immediately (return).

1 Like