Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a single-line comment in Python.
Python
#[1] This is a comment
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using // or /* for comments, which are used in other languages.
Forgetting to put any symbol before the comment text.
✗ Incorrect
In Python, a single-line comment starts with the # symbol.
2fill in blank
mediumComplete the code to write a multi-line comment using triple quotes.
Python
[1] This is a multi-line comment in Python. """
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of triple quotes.
Using four quotes or slashes which are invalid.
✗ Incorrect
Multi-line comments in Python can be written using triple double quotes """ at the start and end.
3fill in blank
hardFix the error in the comment syntax.
Python
print('Hello') [1] This is a comment
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using // or /* which are not valid in Python.
Using -- which is not a comment symbol in Python.
✗ Incorrect
Python uses # for comments. Other symbols cause errors.
4fill in blank
hardFill both blanks to create a dictionary comprehension with a comment inside.
Python
squares = {x: x[1]2 for x in range(1, 6) if x [2] 2 == 0} # even squares Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of ** for power.
Using // instead of % for modulo.
✗ Incorrect
The power operator is ** and the modulo operator is % to check even numbers.
5fill in blank
hardFill all three blanks to create a dictionary comprehension with a comment and condition.
Python
result = { [1]: [2] for [3], [2] in data.items() if [2] > 0} # positive values Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable for key and value.
Using undefined variables.
✗ Incorrect
Use k for keys and v for values in dictionary comprehension.