4. Números aleatorios

1import random
2
3print(random.randint(1, 100))
4print(random.randint(1, 100))
5alumnos = ["José",
6            "Juan",
7            "Pedro",
8            "Lucas",
9            "Thiago"]
10print(random.choice(alumnos))
11print(random.choice(alumnos))
12random.shuffle(alumnos)
13print(alumnos)
14random.shuffle(alumnos)
15print(alumnos)
line that just executed

next line to execute

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

Activity: CodeLens 4.1 (cl_l20_4a)

1import random
2
3
4def codificación(s):
5
6    lista = list(s)
7    random.shuffle(lista)
8    return "".join(lista)
9
10
11print(codificación("palmeras"))
12print(codificación("palmeras"))
line that just executed

next line to execute

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

Activity: CodeLens 4.2 (cl_l20_4b)

1import random
2
3lista = []
4for k in range(15):
5    lista.append(
6        random.randint(10, 100)
7        )
8print(lista)
line that just executed

next line to execute

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

Activity: CodeLens 4.3 (cl_l20_4c)

1import random
2
3lista = []
4while len(lista) < 15:
5    x = random.randint(10, 100)
6    if x not in lista:
7        lista.append(x)
8lista.sort()
9print(lista)
line that just executed

next line to execute

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

Activity: CodeLens 4.4 (cl_l20_4d)

You have attempted 1 of 2 activities on this page