1. File Display
Assume that a file containing a series of integers is named numbers.txt and exists on the computer’s disk. Write a program that displays all of the numbers in the file.
Python program code:
# Open the file in read mode
with open("numbers.txt", "r") as file:
# Read the contents of the file
numbers = file.readlines()
# Iterate over each line in the file
for line in numbers:
# Convert the line to an integer and display it
number = int(line)
print(number)
Data in the file (numbers.txt):
2
30
4111
50
Output of the program code:
2
30
4111
50