0
0
Pythonprogramming~10 mins

Comments in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A#
B!
C//
D/*
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.
2fill in blank
medium

Complete 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'
A'''
B"""
C""""
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of triple quotes.
Using four quotes or slashes which are invalid.
3fill in blank
hard

Fix the error in the comment syntax.

Python
print('Hello') [1] This is a comment
Drag options to blanks, or click blank then click option'
A--
B//
C/*
D#
Attempts:
3 left
💡 Hint
Common Mistakes
Using // or /* which are not valid in Python.
Using -- which is not a comment symbol in Python.
4fill in blank
hard

Fill 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'
A**
B+
C%
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of ** for power.
Using // instead of % for modulo.
5fill in blank
hard

Fill 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'
Ak
Bv
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable for key and value.
Using undefined variables.