Search⌘ K
AI Features

Puzzles 23 to 26

Explore Python 3 puzzles that cover slice assignments, default function arguments, using len() on slices, and working with nested lists. You will understand how sequence modifications affect data, how to use default parameters in functions, and how to access elements in complex list structures. This lesson helps build essential practical skills for Python beginners.

Puzzle 23

What is the output of the following code?

Note: Enter the output you guessed. If your guessed output is a list, enter each element of the list separated by a comma. Then, press the Run button, and your new Elo will be calculated. Don’t forget to save your Elo rating.

Python 3.5
#############################
## id 342
## Puzzle Elo 1104
## Correctly solved 52 %
#############################
customers = ['Marie', 'Anne', 'Donald']
customers[2:4] = ['Barack', 'Olivia', 'Sophia']
print(customers)
Did you find this helpful?

Slice assignment

Slicing helps you to read specific subsequences. Moreover, slice assignments enable you to replace, append, or clear whole subsequences.

In the puzzle, we have a list of customers that are partially replaced by new customers. The puzzle shows how the length of the original sequence may change due to the slice assignment. The slice assignment inserts a list of three customers into the customer list.

A beautiful way to clear the list is:

customers[:] = []

Solution

The correct solution is:

['Marie', 'Anne', 'Barack', 'Olivia', 'Sophia']

Your Elo rating will be updated according to the following table.

Your Elo Correct Incorrect
...