...

/

Puzzles 4 to 6

Puzzles 4 to 6

Understand the difference between comments and strings. Learn the concepts of indexing and string concatenation in Python.

Puzzle 4

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 313
## Puzzle Elo 691
## Correctly solved 78 %
#############################
# This is a comment
answer = 42 # the answer
# Now back to the puzzle
text = "# Is this a comment?"
print(text)

Enter the input below


Comments

There are two types of comments:

  • Block comments:

    Block comments are indented to the same level as the commented code.

  • Inline comments:

    Inline comments are separated by at least two spaces on the same line as the commented code.

The Python standard recommends writing comments as complete sentences. Moreover, the standard discourages using inline comments because they are often unnecessary and clutter the code. Write short and concise code, and do not overuse comments.

This puzzle introduces two basic concepts:

  • First, variables can hold strings. In fact, variables can hold any data type. The data type of a variable can change. You can assign a string to a variable, which is followed by an integer.

  • Second, comments in the code start with the ...

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