0
0
Pythonprogramming~20 mins

Comments in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Python Comments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of code with inline comments
What is the output of this Python code with inline comments?
Python
x = 5  # assign 5 to x
# next line multiplies x by 2
y = x * 2
print(y)  # print the value of y
A5
B10
CSyntaxError
Dnull
Attempts:
2 left
💡 Hint
Look at the calculation done on x before printing y.
Predict Output
intermediate
2:00remaining
Effect of comments on code execution
What will be printed by this code?
Python
a = 3
# a = 10
print(a)
ASyntaxError
B10
C3
Dnull
Attempts:
2 left
💡 Hint
Check which line is commented out.
Predict Output
advanced
2:00remaining
Output with multi-line string used as comment
What is the output of this code?
Python
'''
This is a multi-line string
used as a comment
'''
print('Hello')
ASyntaxError
B
This is a multi-line string
used as a comment
Hello
Cnull
DHello
Attempts:
2 left
💡 Hint
Multi-line strings not assigned to a variable are ignored by Python.
Predict Output
advanced
2:00remaining
Effect of comments inside code block
What will this code print?
Python
for i in range(3):
    # print(i)
    print(i + 1)
A
1
2
3
B
0
1
2
CSyntaxError
Dnull
Attempts:
2 left
💡 Hint
Look at which print statement is active inside the loop.
🧠 Conceptual
expert
2:00remaining
Identifying error caused by misplaced comment
Which option will cause a SyntaxError due to incorrect comment placement?
Aprint(#'Hello')
B#print('Hello')
Cprint('Hello') # This is a comment
Dprint('Hello')
Attempts:
2 left
💡 Hint
Comments cannot start inside a string or expression.