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 14

Text

Consider the following Python function:

def f(n):
    result = list()
    while n > 0:
        result.append(n)
        n = n -1
    return len(result)

What is the result of the execution of f(3)?

Solution

3

Additional material

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