Challenge - 5 Problems
Print Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of print() with multiple arguments
What is the output of this Python code?
Python
print('Hello', 'World', 2024)
Attempts:
2 left
💡 Hint
Remember that print() separates multiple arguments with spaces by default.
✗ Incorrect
The print() function prints each argument separated by a space by default, so the output is 'Hello World 2024'.
❓ Predict Output
intermediate2:00remaining
Using print() with sep parameter
What will this code print?
Python
print('A', 'B', 'C', sep='-')
Attempts:
2 left
💡 Hint
The sep parameter changes the separator between printed items.
✗ Incorrect
The sep='-' tells print() to put a dash between each argument instead of the default space.
❓ Predict Output
advanced2:00remaining
Effect of end parameter in print()
What is the output of this code?
Python
print('Line1', end='***') print('Line2')
Attempts:
2 left
💡 Hint
The end parameter replaces the default newline after print.
✗ Incorrect
By default, print ends with a newline. Here, end='***' replaces it, so the next print continues on the same line after ***.
🧠 Conceptual
advanced2:00remaining
Understanding print() with flush parameter
What does the flush=True parameter do in the print() function?
Attempts:
2 left
💡 Hint
Think about when output appears on the screen.
✗ Incorrect
flush=True forces Python to write the output immediately, useful when output is buffered and you want to see it right away.
❓ Predict Output
expert2: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')
Attempts:
2 left
💡 Hint
Calculate the sum of numbers from 0 to 2 and watch the end parameter.
✗ Incorrect
range(3) is 0,1,2; sum is 3. The end='; ' keeps the cursor on the same line with a semicolon and space before printing 'Done'.