Practice 5
Sample 1
Become very familiar with reading content from a text file. See if you can write a script that creates a simple text file like:
cow
goat
pig
horse
Then your script should loop through each of those lines and print them out. See if you can do it with a for loop, then see if you can do it with a while loop. After you have written your solution, look at my solution here.
Sample 2
Write a program that will download the file found here. Loop through each of the words within the file. As you loop, if the word equals the, replace it with COW. The word a should be replaced with XXXX. The word to should be replaced with 98767. All other words should remain the same.
After you have written your solution, or if you get stuck, check out my solution here
Things to pay attention to:
- Spacing: remember no space around assignment operator, but yes space around comparison operators
==. - Line spacing and indentation don’t matter.
Last Updated 02/07/2025

