1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lina20 [59]
2 years ago
6

1. Your task is to process a file containing the text of a book available as a file as follows:A function GetGoing(filename) tha

t will take a file name as a parameter. The function will read the contents of the file into a string. Then it prints the number of characters and the number of words in the file. The function also returns the content of the file as a Python list of words in the text file.A function FindMatches(keywordlist, textlist): The parameter keywordlist contains a list of words. The parameter textlist contains text from a book as a list of words. For each word in keywordlist, the function will print the number of times it occurs in textlist. Nothing is returned.If you implemented the functions correctly then the following program:booktext = GetGoing('constitution.txt') FindMatches (['War', 'Peace', 'Power'], booktext) Will read the file "constitution.txt" and print something like the following:The number of characters is: 42761The number of words is: 7078The number of occurrences of War is: 4The number of occurrences of Peace is: 2The number of occurrences of Power is: 11
Computers and Technology
1 answer:
Irina18 [472]2 years ago
7 0

Answer:

See explaination

Explanation:

#function to count number of characters, words in a given file and returns a list of words

def GetGoing(filename):

file = open(filename)

numbrOfCharacters =0

numberOfWords = 0

WordList = []

#iterate over file line by line

for line in file:

#split the line into words

words = line.strip().split()

#add counn of words to numberOfWords

numberOfWords = numberOfWords + len(words)

#find number of characters in each word and add it to numbrOfCharacters

numbrOfCharacters = numbrOfCharacters + sum(len(word) for word in words)

#append each word from a line to WordList

for word in words:

WordList.append(word)

#display the result

print("The number of characters: ", numbrOfCharacters)

print("The number of Words: ", numberOfWords)

#return the list of words

return WordList

#find matches for keywords given in textlist

def FindMatches(keywordlist, textlist):

for keyword in keywordlist:

keyword = keyword.lower()

print ("The number of occurrences of {} is: {}".format(keyword,len([i for i, s in enumerate(textlist) if s == keyword])))

#main

booktext = GetGoing("constitution.txt")

FindMatches (['War', 'Peace', 'Power'], booktext)

You might be interested in
Which of the following represent features of free software licensing? Check all of the boxes that apply.
Iteru [2.4K]

Answer: A :is concerned with defending users’ freedom of use

C:makes source code available for editing

Explanation:

7 0
2 years ago
What does a bonus object do? A. Subtracts lives B. Keeps track of a player's health C. Gives a player an advantage D. Makes text
lyudmila [28]

Answer:

C) Gives a player an advantage

Explanation:

I don't know the context of the question, but it makes the most sense.

5 0
3 years ago
FFFFFFFFFRRRRRRRRRRRRRRRRRREEEEEEEEEEEEEEEEEEEEEEE
telo118 [61]

Answer:

THANKS I NEEDED THIS SOOO MUCH!!!$

6 0
3 years ago
Read 2 more answers
What are the main types of reading tools? Check all that apply. please HELP​
vovangra [49]

Answer:

Comprehension

reference

3 0
2 years ago
Which of the following computer component facilitates internet connection?
babunello [35]

Answer:

your answer may be(utility software)

8 0
2 years ago
Read 2 more answers
Other questions:
  • Which activity represents a violation of the licensing agreement
    7·2 answers
  • To move up one paragraph, press the ____ key(s). f1 alt up arrow up arrow ctrl up arrow
    8·1 answer
  • The type of database that is connected by a company's local area networks is a(n:
    11·1 answer
  • Create a class to represent light bulbs
    7·1 answer
  • If you answer I will mark brainliest!!! I want to be able to see two websites on my screen at the same time, how do I do that on
    9·1 answer
  • My game is telling me to "Press any key." Where is the "any" key?????
    13·1 answer
  • ????????????helpppp please
    9·1 answer
  • What happens when you create a variable in a video game program?​
    5·1 answer
  • What technology would a bank's website use a scramble information as it is transmitted over the Internet
    7·1 answer
  • A eclipse occurs at a full moon when the moon passes between earth and the sun
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!