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
"Random Bars" is considered to be a Transition style<br> O True<br> O False
Vesnalui [34]
True….hope it helps love
8 0
2 years ago
9. h=
Nadya [2.5K]

Answer:

rs 35.6ko vrs 12. r7 3.3ko vrt 13.

6 0
2 years ago
A painting company has determined that for every 115 square feet or wall space, one gallon of paint and eight hours of labor wil
Kay [80]

The program to calculate the total paint cost and other values is given below.

#include <iostream>

using namespace std;

int main() {  

 int rooms, laborChrg = 18;

 float paintChrg;

 float feetPerRoom[rooms];  

 float paintReq, laborHrs, paintCost, laborCost, totalCost, totalsqft=0;  

 cout<<"Enter the number of rooms to be painted "<<endl;

 cin>>rooms;  

 for(int i=0; i <= rooms; i++)

 {

 cout<<"Enter the square feet in room "<<endl;

 cin>>feetPerRoom[i];  

 // shortcut operator which is equivalent to totalsqft = totalsqft +     feetPerRoom[i];

 totalsqft += feetPerRoom[i];

 }  

 cout<<"Enter the cost of the paint per gallon "<<endl;

 cin>>paintChrg;  

 laborHrs = (totalsqft/115)*8;

 laborCost = laborHrs * laborChrg;  

 paintReq = totalsqft/115;

 paintCost = paintReq * paintChrg;  

 totalCost = laborCost + paintCost;  

 cout<<"The number of gallons of paint required "<<paintReq<<endl;

 cout<<"The hours of labor required "<<laborHrs<<endl;

 cout<<"The cost of the paint is "<<paintCost<<endl;

 cout<<"The labor charges are "<<laborHrs<<endl;

 cout<<"The Total cost of the paint job is "<<totalCost<<endl;  

 return 0;

}

Explanation:

The header files for input and output are imported.

#include <iostream>

using namespace std;

All the variables are taken as float except labour charge per hour and number of rooms.

The user is asked to input the number of rooms to be painted. An array holds the square feet in each room to be painted.

cout<<"Enter the number of rooms to be painted "<<endl;

cin>>rooms;  

for(int i=0; i <= rooms; i++)

{

cout<<"Enter the square feet in room "<<endl;

cin>>feetPerRoom[i];  

totalsqft += feetPerRoom[i];

}  

The above code asks for square feet in each room and calculates the total square feet to be painted simultaneously.

All the data to be displayed is calculated based on the values of labor charge per hour and gallons of paint needed, given in the question.

laborHrs = (totalsqft/115)*8;

laborCost = laborHrs * laborChrg;

paintReq = totalsqft/115;

paintCost = paintReq * paintChrg;

totalCost = laborCost + paintCost;

All the calculated values are displayed in the mentioned order.

7 0
3 years ago
In some video games, the player cannot obtain the reward without doing what with something that they already have?
Crank

Answer:

risking

Explanation:

8 0
2 years ago
Ron was asked to maintain a database to record the height of every student in class.
Fiesta28 [93]

B. =Compare(B3;B4)

hope I helped!!!

4 0
3 years ago
Read 2 more answers
Other questions:
  • Erick, who is taking an online course, sent an e-mail to his
    14·2 answers
  • What is zenmap typically used for? how is it related to nmap? describe a scenario in which you would use this type of applicatio
    14·1 answer
  • An enterprise system is a packaged software application that helps integrate various ___________ in a company.
    15·2 answers
  • What is the long tube on a microscope called​
    15·1 answer
  • What are the characteristics of the sorting and grouping options in Outlook? Check all that apply. Columns can be sorted by clic
    15·2 answers
  • Question 1 (1 point)
    5·2 answers
  • Look at the picture ​
    13·2 answers
  • Wight an essay on Knowledge sharing among robots.<br> please and please do not delete my question.
    7·1 answer
  • Sara wants to set up her lights to turn on when she arrives home. She has heard that she might be able to do this using IoT. Wha
    12·2 answers
  • Screen reading for extended periods can cause___________ _____________, so the position the monitor to minimize glare and give y
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!