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]
3 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]3 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
C) Explain GIGO briefly.​
hodyreva [135]

Answer:

Is is also a computer science acronym that implies bad input will result in bad output. Requiring valid input also helps programs avoid errors that can cause crashes and other erratic behavior.

IT'S FORMULA IS GIGO: GARBAGE IN GARBAGE OUT...

HOPE IT'S HELPFUL FOR U!!

AND PLZ MARK ME AS BRAINLIEST IF U LIKE THIS ANSWER!!!!

4 0
3 years ago
Match the item to the type.
I am Lyosha [343]

Answer:

a. hardware - 3. motherboard

b. software - 2. Microsoft Word

c. input device - 4. mouse

d. operating system - 1. windows

7 0
3 years ago
Read 2 more answers
Given an unsorted std::vector and a number n, what is the worst-case time complexity for finding the pair of integers whose sum
kari74 [83]

Answer:A

Explanation:

8 0
4 years ago
At the dsl local carrier's office, the __________ demultiplexes the data streams and converts them into digital data.
den301095 [7]

At the DSL (Digital Subscriber Line) local carrier's office, the  DSLAM demultiplexes the data streams and converts them into digital data.

DSLAM stands for Digital Subscriber Line Access Multiplexer. It is a network device, usually at a telephone company central office that aggregates individual subscriber lines  into a high-capacity uplink.

3 0
3 years ago
A _____ diagram is used to identify causes to a problem.
erik [133]

Answer:

fishbone

Explanation:

6 0
3 years ago
Other questions:
  • Tablets combine the features of which two types of devices?
    10·2 answers
  • Description A data retrieval tool that finds specified data within a database A collection of records All of the fields for a si
    7·1 answer
  • Which of the following is a negative impact of technology on society
    9·1 answer
  • True or false questions. If a statement is false, you must explain the reason why it is false: a). Suppose that TCP is being run
    12·2 answers
  • What is a special character when creating a password?
    8·2 answers
  • Name the written test a potential driver must pass and list the minimum required score to earn a learner’s license.
    8·2 answers
  • HTML question please help
    5·1 answer
  • 1. what is another name for CPU?
    6·1 answer
  • How many voltage values can be represented with a 10-bit binary code?
    15·1 answer
  • David is preparing a report to show the percentage increase in population in the United States in the last five years. Which fea
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!