Answered step by step
Verified Expert Solution
Question
1 Approved Answer
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started