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
Eddi Din [679]
2 years ago
14

Write a function named lineStats. The function lineStats takes three parameters: 1.inFile, a string that is the name of an input

file 2.outFile, a string that is the name of an output file 3.threshold, an int that is the length above which a word is considered significant The function lineStats should read and analyze each line of the input file and write two statistics, separated by a space, about the line to a corresponding line of the output file. The two statistics for each line are: 1.the number of words 2.the number of distinct significant words (that is, words longer than threshold) Hint: if a word occurs more than once on a line it counts as a single word. Upper and lower case characters are considered the same ('Word' and 'word' are the same word). The input file contains only upper and lower case letters and white space. For example, if the file fish.txt contains the following lines: Yes some are red and some are blueSome are old and some are newThen the function call: lineStats('fish.txt', 'fishOut.txt', 3)should produce an output file fishOut.txt with the following content: 8 27 1
Computers and Technology
1 answer:
luda_lava [24]2 years ago
5 0

Answer:

See explaination

Explanation:

def lineStats(inFile,outFile,threshold):

# opening the input file

f=open(inFile)

# opening the file for writing output

f2=open(outFile,'w')

# reading every line in the file

for line in f:

# removing the space

line=line.strip()

# splitting the line by space

words=line.split()

# writing the number of words to the outfile file

f2.write(str(len(words))+' ')

# counter variable

count=0

# empty list

t=[]

# for every word in the words list

for word in words:

# changing the word to lower case

word=word.lower()

# checking for the length of the word greater than threshold

if len(word) > threshold:

# if the word is not in the list 't'

if word not in t:

# appending the word into the list 't'

t.append(word)

# writing the number of threshold words to the output file

f2.write(str(len(t))+'\n')

# closing the files

f.close()

f2.close()

# testing

if __name__=='__main__':

lineStats('fish.txt','fishOut.txt',3)

CONTENTS OF fish.txt:

Yes some are red and some are blue

Some are old and some are new

CONTENTS OF fishOut.txt:

8 2

7 1

CLASS CODE:

PYTHON CODE(state.py):

class State:

'''

State class is used to represent a state in a country.

'''

# constructor

def __init__(self,name):

self.name=name

self.universities=[]

# method to add university to the state

def addUniversity(self,university):

self.universities.append(university)

# method to check university is in the state or not

def is_home_of(self,university):

if university in self.universities:

return True

else:

return False

PYTHON CODE (state_test.py):

from state import State

newjersey=State('New Jersey')

newjersey.addUniversity('NJIT')

newjersey.addUniversity('Princeton')

print('New Jersey is the home of MIT :',newjersey.is_home_of('MIT'))

You might be interested in
Complete the statement below with the correct term.
nikitadnepr [17]

Answer:

DOMAIN

Explanation:

A utility that provides names to each computer on a network is called a DOMAIN naming service.

4 0
3 years ago
An array name is a pointer constant because the address stored in it cannot be changed during runtime.
choli [55]
The answer to your question would be option B- False
5 0
2 years ago
Read 2 more answers
Practice using word processing software, including creating, formatting, and saving a document.
irakobra [83]

When writing the cover letter, the following points are important:

  • Keep it short.
  • Proofread.
  • Avoid cliches.
  • Be creative.

<h3>What is a cover letter?</h3>

A cover letter simply means a document that's written alongside a CV when an individual applies for jobs.

The cover letter should be addressed to a specific person and should describe one's accomplishments and achievements.

Learn more about cover letters on:

brainly.com/question/3602860

6 0
2 years ago
In this problem, you will write three methods to:
gulaghasi [49]

Answer:

see explaination for program code

Explanation:

program code below:

class Names{

public static String[] makeNames(String[] array1, String[] array2){

if(array1.length == 0) return array2;

if(array2.length == 0) return array1;

String[] res = new String[array1.length*array2.length];

int k = 0;

for(int i=0;i<array1.length;i++){

for(int j=0;j<array2.length;j++){

res[k++] = array1[i] + " " + array2[j];

}

}

return res;

}

public static String[] makeNames(String[] array1, String[] array2, String[] array3){

return makeNames(makeNames(array1, array2), array3);

}

public static void print(String[] array){

for(String name : array){

System.out.println(name);

}

}

public static void main(String[] args) {

String[] first = {"David", "Mike", "Katie", "Lucy"};

String[] middle = {"A","B", "C", "D", "E"};

String[] last = {};

String[] names = makeNames(first, middle, last);

print(names);

print(names);

}

}

8 0
3 years ago
Describe the benefits of digital technology. Eric reads interesting information about MP3 players and wants to buy one. Which of
Otrada [13]

Answer:

b. Play music

Explanation:

Digital technology helps improve an existing process and makes things better. In this scenario of an MP3 player, digital technology takes care of music. Before a portable MP3 player came into the picture, people had to carry large physical records or multiple CD packs but now, a small device can hold thousands of those same songs in it.

4 0
2 years ago
Other questions:
  • If you plan on operating several applications at s time, the amount of RAM should be considered when purchasing a computer
    10·2 answers
  • Which term refers to an interface between HTML elements and JavaScript program code that allows JavaScript code to manipulate HT
    12·1 answer
  • All users on the network have antivirus software; however, several users report that they have what an administrator described a
    10·1 answer
  • "This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some out
    15·1 answer
  • Which of the following kinds of software is a sophisticated type of application software that assists a professional user in cre
    5·1 answer
  • Can anyone find any words in here?
    14·2 answers
  • Amye is in high school. As part of one of her classes, she had to identify the legality of different situations that involved
    10·2 answers
  • What is a written or electronic document that outlines etiquette policies for using networks and network resources?
    8·1 answer
  • Which SCSI standard allows for the technique known as “hot swapping”? Ultra SCSI Original SCSI Serial SCSI Fast-Wide SCSI
    5·1 answer
  • Which type of software is created on user dimension​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!