Search⌘ K
AI Features

Puzzles 19 to 22

Explore Python code puzzles 19 to 22 to understand string slicing, handling arbitrary function arguments, and indirect recursion. This lesson helps you develop problem-solving skills by applying these concepts in progressively challenging puzzles and tracking your performance with Elo ratings.

Puzzle 19

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.

Python 3.5
#############################
## id 334
## Puzzle Elo 954
## Correctly solved 45 %
#############################
word = "galaxy"
print(word[:-2] + word[-2:])
Did you find this helpful?

Slicing

Slicing, like indexing, retrieves specific characters from a sequence, such as a string. But while indexing retrieves only a single character, slicing retrieves a whole substring within an index range.

Use the bracket notation for slicing with the start and end position identifiers. For example, word[i:j] returns the substring starting from index i (included) and ending in index j (excluded).

You can also skip the position identifier before or after the slicing colon. This indicates that the slice starts from the first or last position, respectively.

word[:i] + word[i:] returns the same string as word.


Solution

The correct solution is galaxy.

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

Your Elo Correct Incorrect
0 - 500 47 -8
500 - 1000 38 -17
1000 - 1500 14
...