Chapter 6: Problem 14
Assume that the file data.txt exists and contains several lines of text. Write a short program using the while loop that displays each line in the file.
Short Answer
Expert verified
Based on the provided step-by-step solution, answer the following question:
**Question:** Write a short program using a while loop that reads and displays each line from the file "data.txt".
**Answer:** Here is a short program that reads and displays each line from the file "data.txt" using a while loop:
```python
file = open("data.txt", "r")
line = file.readline()
while line:
print(line, end="")
line = file.readline()
file.close()
```