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 18

Text

Consider the following Python function:

def f(x, y, z):
    if x == y:
        return z[:x] 
    else:
        return z[:y]

What is the result of the execution of f(6, 3, "let it snow")?

Solution

"let"

Additional material

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