Lists
Answers are for parents and teachers.
1
Start with numbers = [3, 6, 9]. Write the list after append(12), then remove(6), then numbers[0] = 1.
[3, 6, 9, 12], then [3, 9, 12], then [1, 9, 12].
2
What happens with this code, and why?
Python
1names = ["Mona", "Sami"] 2names.remove("Adam")
Output
ValueError: the value is not in the list
Python stops with a ValueError, because there is no Adam in the list.
3
Fill the table for the invented strings, using the four checks. Which string scores highest?
| Invented string | length 8+ | digit | capital | symbol | score |
|---|---|---|---|---|---|
| "cat" | 0 | 0 | 0 | 0 | 0 |
| "Sunny2024" | 1 | 1 | 1 | 0 | 3 |
| "tree!" | 0 | 0 | 0 | 1 | 1 |
| "ABCDEFGH" | 1 | 0 | 1 | 0 | 2 |
Sunny2024 scores 3 (length, digit, capital); tree! scores 1; ABCDEFGH scores 2; cat scores 0. Sunny2024 is highest.
4
Write the steps (not code) of a program that prints the names in ["Mona", "Omar", "Salma", "Sami"] that start with O.
Loop over the names; if the first character is O, print the name. It prints Omar.
5
A friend wants to test the strength program with the real password of their account. What do you say?
Do not do it. Use an invented string. A real password must stay secret and should never be typed into a practice program.