Puzzles 27 to 30
Explore Python puzzles 27 to 30 that challenge your understanding of list slicing to clear sublists, the Fibonacci series algorithm, using the modulo operator with the continue statement, and indexing with the range function. Learn how to predict outputs, apply Python features like iterable unpacking, and improve your programming skills through hands-on practice with feedback on your Elo rating.
Puzzle 27
What is the output of the following code?
Note: Enter the output you guessed. Then, press the Run button, and your new Elo will be calculated. Don’t forget to save your Elo rating.
Clearing sublists
In verbose programming languages such as Java, you have to iterate over a list to remove subsequent elements. In Python, a simple one-liner does that for you. Use the slice notation to select a sequence of items in the list. This is the left-hand side of your equation. Then, overwrite the selected sequence with the empty (or any other) list.
Solution
The correct solution is ['a'].
Your Elo rating will be updated according to the following table.
| Your Elo | Correct | Incorrect |
|---|---|---|
| 0 - 500 | 47 | -8 |
| 500 - 1000 | 45 | -10 |
| 1000 - 1500 | 27 | -28 |
| 1500 - 2000 | 10 | -45 |
| >2000 | 8 | -47 |
Puzzle 28
What is the output of the following code?
Note: Enter the output you guessed. If your guess is multi-lined, enter each value separated by the spacebar. Then, ...