Question #696

What is the output of the code snippet below?
def verify(num1, num2):
    if num1 > num2:
        return num1
    elif num1 == num2:
        return True
    else:
        return num2


def display(arg1, arg2):
    if verify(arg1, arg2) == arg1:
        print("A")
    elif verify(arg1, arg2):
        print("C")
    else:
        print("B")


display(1000, 3500)

Watch the trap! A function that returns anything that is not False or 0 will be evaluated as True within an if statement. Here, if verify(arg1, arg2): always evaluates to True . (docs.python.org/3/reference/expressions.html#boolean-oper...)


Comment on Disqus:

Question difficulty: 🔵🔵🔵🔵🔵


Similar questions: