...

/

Puzzles 27 to 30

Puzzles 27 to 30

Learn about clearing sublists, Fibonacci series, continue statement, modulo operator, indexing, and range sequence in Python.

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.

Press + to interact
Elo
1000
#############################
## id 343
## Puzzle Elo 1248
## Correctly solved 47 %
#############################
letters = ['a', 'b', 'c',
'd', 'e', 'f', 'g']
letters[1:] = []
print(letters)

Enter the input below

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 ...

Access this course and 1400+ top-rated courses and projects.