Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a PYTHON program only using if-elif-else, loops, and reading from file and avoiding any other advanced material Question 2: Counting Words In this question

write a PYTHON program only using if-elif-else, loops, and reading from file and avoiding any other advanced material image text in transcribed
Question 2: Counting Words In this question you will write a program that asks the user to enter two filenames. One file contains a list of words that you want to count. For the followingexplanation, let's call it words.txt. (When your program runs, the user could type a different name. Do not hardcode any filenames in your code.) The second file contains the text that you want to search for each word. For the explanation, let's call it story.txt Ask the user to enter the name of each file. Assume that the files are located in the same directory as your code file. For each word in words.txt, search through story.txt and count how many times the word occurs. Print a summary similar to the sample output below. Note 1: You should consider a "word" to be anything bounded by whitespace. You do not need to do any processing to account for punctuation or other special characters. For example, in the sample below,"time." (with a period) is not considered the same as the word "time" (without a period). Capitalization will also matter. "The" will not be considered the same word as "the". Note 2: You should test your program with small files of your own creation, until you are sure that the counting is correct. Your program will be tested with word files containing 10-20 words, and fairly large story files obtained from Project Gutenberg (https://www.gutenberg.org). Download a book of your choice from Project Gutenberg, and verify that your program works with a large file. Sample input file, words.txt: a time Sample input file, story.txt: Once upon a time there was a dog. The dog ran around and around, and had a great time. The end. Sample program output(blue text is typed by the user): Enter the name of the file containing the words to count: words.txt Enter the name of the file containing the story: story.txt The word "a" occurs 3 times. The word "time" occurs 1 times. Program terminated normally

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions