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
How does one build social capital?
iren2701 [21]

Answer:

by building on line presence

Explanation:

If you put yourself out there in multiple social sites you will build a following

3 0
2 years ago
What does obsolete mean?
Alex
No longer produced or used; out of date.
8 0
2 years ago
Read 2 more answers
How do design elements and color work together on a web page?
KiRa [710]

Answer:

The answer I believe is: 2. Both Enhance visual appeal.

Explanation:

4 0
2 years ago
Which phone has the most GB (Gigo Bites)<br><br>A.Samsung<br>B.Iphone<br>C.LG<br>D.ZTE
Lina20 [59]
It's GigaBytes actually. And is it RAM or storage capabilities?

And also those are brands. Not models. For example, Samsung has different phones. Not just one.


7 0
3 years ago
Read 2 more answers
........ manages the function of all the hardware and other software used in the computer.
Ivenika [448]

Answer:

The answer to this question is given below is in the explanation section.

Explanation:

manages the function of all the hardware and other software used in the computer:

operating system is defined as a system software that manages computer hardware and software resources and provide common services for computers programs.All application software computer programs requires an operation system to  function. operating system controls computer hardware run the computer programs and organize file.

CPU:

central processing unit that bring the instruction from memory to be executed and decodes.

Storing device:

Any hardware that can hold information temporarily and permanently. we distinguish two type of storage: as primary storage device and a secondary storage device.

Example:

  1. Magnetic storage device:hard drive,floppy diskette etc.
  2. optical: Blu-ray disc,CD Rom disc.

Flash memory device:memory card memory sick,ssd

Hardware:

Hardware include the physical features,which are every part that you can either see or touch, for example monitor,case,keyboard,mouse and printer.

Software:

The part which activate the physical components called software. it includes the features that resposible for directing the work to the hardware.

8 0
3 years ago
Other questions:
  • Data cannot be sorted of filtered accurately if there are ________.
    10·2 answers
  • What is data protection
    13·1 answer
  • Write a program that reads raw data from a file that contains an inventory of items. The items should be sorted by name, and the
    12·1 answer
  • When microsoft introduced its zune mp3 player, many people thought it would capture the mp3 player market by pricing its product
    8·1 answer
  • Hydraulic systems use liquids because _____.
    14·2 answers
  • A _____ network is where all computers are equal and each one is both data requester and data provider.
    13·1 answer
  • What help in executing commands quickly
    5·1 answer
  • Please answer this question​
    8·1 answer
  • How was data put into the Tabulating Machine?
    7·1 answer
  • Do you want my hero academia?<br><br><br><br><br><br> if so, who's your favorite character :&gt;
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!