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
To generate a series of first ten counting number of algorithm​
Anettt [7]
Uhh i need points so i don’t fail math.
3 0
2 years ago
Which of the following expressions yields an integer between 0 and 100, inclusive? Question 5 options: (int)(Math.random() * 100
Alex17521 [72]

Answer:

(b) (int)(Math.random() * 101)

Explanation:

Given

min = 0 --- minimum

max =100 --- maximum

Required

Java expression to generate random integer between the above interval

The syntax to do this is:

(int)(Math.random((max - min) + 1) + min)

Substitute the values of max and min

(int)(Math.random((100 - 0) + 1) + 0)

Simplify the expression

(int)(Math.random(100 + 1) + 0)

(int)(Math.random(101) + 0)

(int)(Math.random(101))

Hence, the right option is:

(b) (int)(Math.random() * 101)

3 0
2 years ago
If a surface is. it is exactly vertical
Jobisdone [24]
What are the choices
8 0
3 years ago
What is another word for microchips operating systems input methods and everything in between?
lord [1]
The answer is computer. A computer is made up of microchips (CPU and GPU), an operation system (macOS or Windows), input methods (keyboard and mouse), and other parts.
7 0
3 years ago
"If someone really wants to get at the information, it is not difficult if they can gain physical access to the computer or hard
Jobisdone [24]

Answer:

It is  just true in most cases

Explanation:

This statement is just true in most cases because in some cases having a physical access to the computer or hard drive this does not guarantee access to the information contained in the hard drive or computer because the data/information in the hard drive or computer might as well be encrypted and would require a password in order to de-crypt the information.

Having a physical access is one step closer in some cases but not the only step required .

4 0
3 years ago
Other questions:
  • ____ indicates the number of pixels that a computer uses to display the letters, numbers, graphics, and background on a screen.
    12·2 answers
  • Ryan has created a Word document to be used as a review quiz for students in a classroom setting. The document contains both que
    6·1 answer
  • Help please brainliest
    8·1 answer
  • What is one of the most effective security tools available for protecting users from external threats?
    15·1 answer
  • Sam needs to create a spreadsheet for his coworkers. They will need to follow a crossed a long road of data. Sam would like to m
    15·1 answer
  • You have a large TCP/IP network and want to keep a host's real time clock synchronized. What protocol should you use?
    10·1 answer
  • Menus are attached to the windows by calling
    15·1 answer
  • Finish the program by choosing the correct terms.
    7·2 answers
  • Basics of visual basic
    15·2 answers
  • The rectangular symbol in flowchart<br> is used to denote dash
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!