4. Random numbers

1import random
2
3print(random.randint(1, 100))
4print(random.randint(1, 100))
5students = ["Jose",
6            "Juan",
7            "Pedro",
8            "Lucas",
9            "Thiago"]
10print(random.choice(students))
11print(random.choice(students))
12random.shuffle(students)
13print(students)
14random.shuffle(students)
15print(students)
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_en)

1import random
2
3
4def codification(s):
5
6    lst = list(s)
7    random.shuffle(lst)
8    return "".join(lst)
9
10
11print(codification("palmeras"))
12print(codification("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_en)

1import random
2
3lst = []
4for k in range(15):
5    lst.append(
6        random.randint(10, 100)
7        )
8print(lst)
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_en)

1import random
2
3lst = []
4while len(lst) < 15:
5    x = random.randint(10, 100)
6    if x not in lst:
7        lst.append(x)
8lst.sort()
9print(lst)
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_en)

You have attempted 1 of 2 activities on this page