0
0
Pythonprogramming~20 mins

Writing multiple lines in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-line Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of multi-line string with triple quotes
What is the output of this Python code?
Python
text = '''Hello
World
Python'''
print(text)
AHello\nWorld\nPython
BHello World Python
C
Hello
World
Python
DHello\ World\ Python
Attempts:
2 left
💡 Hint
Triple quotes preserve new lines inside the string.
Predict Output
intermediate
2:00remaining
Output of multiple print statements
What will be printed by this code?
Python
print('Line 1')
print('Line 2')
print('Line 3')
ALine 1 Line 2 Line 3
BLine 1\nLine 2\nLine 3
CLine 1, Line 2, Line 3
D
Line 1
Line 2
Line 3
Attempts:
2 left
💡 Hint
Each print outputs a new line by default.
Predict Output
advanced
2:00remaining
Output of multi-line string with escape sequences
What is the output of this code?
Python
text = """First line
Second line	Tabbed
Third line"""
print(text)
AFirst line\nSecond line\tTabbed\nThird line
B
First line
Second line	Tabbed
Third line
CFirst line Second line Tabbed Third line
DFirst line\ Second line\ Tabbed\ Third line
Attempts:
2 left
💡 Hint
Escape sequences like \n and \t are interpreted inside triple quotes.
🔧 Debug
advanced
2:00remaining
Identify the error in multi-line string usage
What error does this code raise?
Python
text = '''This is a multi-line string
without closing quotes
print(text)
ASyntaxError
BTypeError
CIndentationError
DNameError
Attempts:
2 left
💡 Hint
Check if all quotes are properly closed.
🧠 Conceptual
expert
2:00remaining
How many lines does this multi-line string contain?
How many lines will the variable 'text' contain after this code runs?
Python
text = '''Line1
Line2

Line4'''
A4
B3
C2
D5
Attempts:
2 left
💡 Hint
Count all lines including empty ones created by \n.