...

/

Puzzles 19 to 22

Puzzles 19 to 22

Understand the concept of slicing, concatenation, arbitrary arguments, and indirect recursion in Python.

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.

Press + to interact
Elo
1000
#############################
## id 334
## Puzzle Elo 954
## Correctly solved 45 %
#############################
word = "galaxy"
print(word[:-2] + word[-2:])

Enter the input below


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