Question: Create a Python program that takes a txt file named myfile.txt as a command line argument, opens it , and writes in it . The

Create a Python program that takes a txt file named myfile.txt as a command line argument, opens it, and writes in it. The program should be named write.py. This program should: Take two files as arguments (write.py, myfile.txt). Once again, even though you have the py file as your first argument, you dont need to write this in the Run...Customized menu. Check for the number of arguments and exit with a message if there arent exactly 2. Open the text file for writing. Write the words cows,pigs,dogs,birds,cats,chickens into the text file all on separate lines. Close the file. This program should take no input from the user and give no output in the IDLE shell. It should create a file named myfile.txt. QUESTION 2: Create a python program that takes the text file we created in the last questions as a command line argument, opens it, and reads it. It should be named read.py. This program should: Take two files as command line arguments (read.py, myfile.txt) Check for the number of arguments and exit with a message if there arent exactly 2. Open the text file for reading. Print the sentence The farm has ___, for every animal in myfile.txt. Close the file. This program should take no input from the user but give an output. Example Output: The farm has cowsThe farm has pigsThe farm has dogsThe farm has birdsThe farm has cats QUESTION 3: Create a python program that takes three arguments, Two of those three arguments are text files as command line arguments, opens one for reading and one for writing, then writes the contents of the first text file into the second text file, changing them all to uppercase. The program should be named upper.py. This program should: Take the text file we made in question 1(myfile.txt) and a new text file (uppercase.txt) as arguments. Open myfile.txt for reading and uppercase.txt for writing. Check to see the number of system arguments, if the number of arguments isnt equal to three, quit with a message. Take the text from the first file and put it into the second file, this time capitalized. Close the files. This program should take no input from the user and return no output. It should create a new text file uppercase.txt. QUESTION 4: Create a Python program that takes two files as an argument. The second file is a text file as a command line argument. The program opens the text file and counts the number of times the word apple appears in the file, upper or lower case. The program should be named apple.py. This program should: Take example.txt file as the second argument. Check to see the number of system arguments, if the number of arguments isnt equal to two, quit with a message. Open the text file for reading. Count the number of times the word apple appears in the file. Print the number of times the word apple appeared. Close the text file. Case shouldnt matter, ApPle: and apple both count. However, apple has to be isolated, hiapple shouldn't be counted. Example Output: The word apple appears 8 times in example.txt. QUESTION 5: Create a python program that takes two text files as a command line argument and compares the number of characters in each text file. The program should be named compare.py This program should: Take any two text files as command line arguments. Check to see the number of system arguments. If the number of arguments is not equal to 3, exit with a message. Open both text files for reading. Count the number of characters in each text file (not including spaces). Compare the number of characters in each text file and print the output. Close both files. This program should take no input from the user and print an output. Example Output: example1.txt has more characters than example2.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!