Question: - Write a Python function named readWords having a single string parameter corresponding to a filename. - Your function must open the file for reading,

- Write a Python function named readWords having a single string parameter corresponding to a filename. - Your function must open the file for reading, and then read each line of the file line-by-line. - Each line of the file will contain one word. - Build and return a single string of all words in the file, each separated in the new string by a single space. Example: For the file shown to the left, calling your function with the filename "words.txt": def main(): string = readWords ("words.txt") print(string) \# prints the string: \# "I was chewing gum for something to do." - Write a Python function named readWords having a single string parameter corresponding to a filename. - Your function must open the file for reading, and then read each line of the file line-by-line. - Each line of the file will contain one word. - Build and return a single string of all words in the file, each separated in the new string by a single space. Example: For the file shown to the left, calling your function with the filename "words.txt": def main(): string = readWords ("words.txt") print(string) \# prints the string: \# "I was chewing gum for something to do
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
