Question

python program 1. create a .txt file and call it fruits.txt, add the following items to...

python program

1. create a .txt file and call it fruits.txt, add the following items to the file

Apple

Banana

Peach

Strawberry

Watermelon

Kiwi

Grape

2. Write a program that does the following:

- Reads the fruit.txt

- Converts the contents into all uppercase

- Writes the uppercased values into a text file called "UpperFruit.txt"

OUTPUT SHOULD BE:

APPLE

BANANA

PEACH

STRAWBERRY

WATERMELON

KIWI

GRAPE

Homework Answers

Answer #1

# problem 1
file = open('fruits.txt', 'w')
fruits = ["Apple\n","Banana\n","Peach\n","Strawberry\n","Watermelon\n","Kiwi\n","Grape\n"]
file.writelines(fruits)
file.close()

# problem 2
inpFile = open('fruits.txt', 'r')
outFile = open('UpperFruit.txt', 'w')

lines = inpFile.readlines()

for line in lines:
   outFile.write(line.upper())

inpFile.close()
outFile.close()

OUTPUT

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program in python that takes a txt file and converts it to html
Write a program in python that takes a txt file and converts it to html
#python program Read and Write to PDF Read txt, docx Create converter for taking the imported...
#python program Read and Write to PDF Read txt, docx Create converter for taking the imported documents and converting to .txt for parsing Create converter from .txt of python summary output to PDF Create converter from .txt of python summary output to .doc Add this functionality through a gui
I need python code for this. Write a program that inputs a text file. The program...
I need python code for this. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take precedence over lowercase words. For example, 'Z' comes before 'a'. The input file can contain one or more sentences, or be a multiline list of words. An example input file is shown below: example.txt the quick brown fox jumps over the lazy dog An example of the program's output...
The following code to run as the described program on python. The extra test file isn't...
The following code to run as the described program on python. The extra test file isn't included here, assume it is a text file named "TXT" with a series of numbers for this purpose. In this lab you will need to take a test file Your program must include: Write a python program to open the test file provided. You will read in the numbers contained in the file and provide a total for the numbers as well as the...
c# please Create a “Main” program which reads a text file called “collectionOfWords.txt”. Include exception handling...
c# please Create a “Main” program which reads a text file called “collectionOfWords.txt”. Include exception handling to check if the file exists before attempting to open it. Read and print each string to the console. Next modify each word such at the first letter in each word is uppercase and all other letters are lowercase. Display the modified word on the console. Creating a text file: Open up Notepad and type in the following words. Save the file as collectionOfWords.txt...
** Language Used : Python ** PART 2 : Create a list of unique words This...
** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
Consider the following file arrest.dat containing information of a suspect that the police is looking for:...
Consider the following file arrest.dat containing information of a suspect that the police is looking for: arrest.dat: The police is looking for Robert Whiteshead, also known as Whity, ID number 4607091111027, from address 4 Azalea Court, 219 Belmont Street, Germiston, 2065, in connection with a bank robbery at UNITED BANK in January 2016. An amount of about R45,000,000 was stolen on this day. Apparently he had a helper that goes by the name of JOINT13. Mr Whiteshead was also an...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT