Practice Exercises Files: Exercise 1
Practice Exercises Files: Exercise 1
Exercises Files
Exercise 1:
Create a program that opens file.txt. Read each line of the file and prepend it with a line
number.
The contents of files.txt:
This is line one.
This is line two.
Finally, we are on the third and last line of the file.
Sample output:
1: This is line one.
2: This is line two.
3: Finally, we are on the third and last line of the file.
Exercise 2:
Read the contents of animals.txt and produce a file named animalssorted.txt that is sorted
alphabetically.
The contents of animals.txt:
man
bear
pig
cow
duck
horse
dog
LinuxTrainingAcademy.com
After the program is executed the contents of animalssorted.txt should be:
bear
cow
dog
duck
horse
man
pig
LinuxTrainingAcademy.com