Challenge - 5 Problems
Print Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of print() with sep and end parameters
What is the output of this Python code?
print('A', 'B', 'C', sep='-', end='!')
print('D')Python
print('A', 'B', 'C', sep='-', end='!') print('D')
Attempts:
2 left
💡 Hint
Remember that
sep changes the separator between items and end changes what is printed at the end.✗ Incorrect
The
sep='-' makes the items print separated by dashes. The end='!' means the first print does not add a newline but an exclamation mark. So the second print starts immediately after the exclamation mark.❓ Predict Output
intermediate2:00remaining
Using flush parameter in print()
What does this code print?
import sys
print('Hello', flush=True)
print('World', flush=False)Python
import sys print('Hello', flush=True) print('World', flush=False)
Attempts:
2 left
💡 Hint
The flush parameter forces the output buffer to write immediately.
✗ Incorrect
Both print statements add a newline by default. The flush parameter does not change output content, only when it is sent to the screen. So the output is two lines: Hello and World.
❓ Predict Output
advanced2:00remaining
Formatted string with print() and f-string
What is the output of this code?
name = 'Sam'
age = 7
print(f'{name} is {age} years old.')Python
name = 'Sam' age = 7 print(f'{name} is {age} years old.')
Attempts:
2 left
💡 Hint
f-strings replace variables inside curly braces with their values.
✗ Incorrect
The f-string evaluates variables inside {} and inserts their values. So it prints 'Sam is 7 years old.'.
❓ Predict Output
advanced2:00remaining
Using print() with multiple end parameters
What is the output of this code?
print('X', end='-')
print('Y', end='*')
print('Z')Python
print('X', end='-') print('Y', end='*') print('Z')
Attempts:
2 left
💡 Hint
Each print uses its own end parameter to decide what to print after the content.
✗ Incorrect
The first print ends with '-', second ends with '*', third ends with default newline. So output is 'X-Y*Z' followed by newline.
🧠 Conceptual
expert2:00remaining
Understanding print() with file parameter
What happens when you run this code?
import sys
print('Error message', file=sys.stderr)Python
import sys print('Error message', file=sys.stderr)
Attempts:
2 left
💡 Hint
The file parameter directs print output to a specific stream.
✗ Incorrect
Using file=sys.stderr sends the printed text to the error output stream, which is separate from standard output.