Python Code Reorder Medium +20 XP
File Reading Pattern
Reorder to read a file properly.
Click lines in the correct order
Available lines3 left
Your order
Click lines above to build your solution.
Show answer and explanation
Answer: with open("data.txt", "r") as file:
for line in file:
print(line.strip())
Open the file with 'with' context manager first, then iterate, then process each line.
Hint: Open the file before reading it.
What this challenge tests
Code Reorder in Python: files, context-manager.