2. Funciones def

1def es_par(x):
2    return x % 2 == 0
3
4
5print(es_par(13))
6print(es_par(12))
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 2.1 (cl_l20_2a)

2.1. Ejemplo

  • Definir una función factorial

1def factorial(n):
2    f = 1
3    while n > 0:
4        f = f * n
5        n = n - 1
6    return f
7
8
9for i in range(5):
10    print(factorial(i))
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 2.1.1 (cl_l20_2b)

You have attempted 1 of 2 activities on this page