The CTP Book

A book for teaching Computational Thinking and Programming skills to people with a background in the Humanities

View on GitHub

Understanding - Beginner, exercise 10

Text

Consider the following Python function:

def f(s1, s2, n):
    if s1 < s2:
        return n
    else:
        return f(s2, s1, n * -1)

What is the result of the execution of f("mickey","donald",7)?

Solution

-7

Additional material

The runnable Python file is available online. You can run it executing the command python exercise_10.py in a shell.