0
0
Pythonprogramming~20 mins

print() function basics in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Print Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of print() with multiple arguments
What is the output of this Python code?
Python
print('Hello', 'World', 2024)
AHello, World, 2024
B'Hello' 'World' 2024
CHello World 2024
DHelloWorld2024
Attempts:
2 left
💡 Hint
Remember that print() separates multiple arguments with spaces by default.
Predict Output
intermediate
2:00remaining
Using print() with sep parameter
What will this code print?
Python
print('A', 'B', 'C', sep='-')
AA-B-C
BA B C
CABC
DA, B, C
Attempts:
2 left
💡 Hint
The sep parameter changes the separator between printed items.
Predict Output
advanced
2:00remaining
Effect of end parameter in print()
What is the output of this code?
Python
print('Line1', end='***')
print('Line2')
ALine1***Line2
BLine1 Line2
C
Line1
Line2
DLine1***\nLine2
Attempts:
2 left
💡 Hint
The end parameter replaces the default newline after print.
🧠 Conceptual
advanced
2:00remaining
Understanding print() with flush parameter
What does the flush=True parameter do in the print() function?
AIt delays the output until the program ends.
BIt changes the separator between printed items.
CIt adds a newline after the printed text.
DIt forces the output to be written immediately to the screen or file.
Attempts:
2 left
💡 Hint
Think about when output appears on the screen.
Predict Output
expert
2:00remaining
Output of print() with complex expressions
What is the output of this code?
Python
print(f"Sum: {sum([i for i in range(3)])}", end='; ')
print('Done')
ASum: 6; Done
BSum: 3; Done
C
Sum: 3
Done
D
Sum: 6
Done
Attempts:
2 left
💡 Hint
Calculate the sum of numbers from 0 to 2 and watch the end parameter.