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]
3 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]3 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
If your BAL is .10 you can expect a _______ drop in complex performance compared to the sober level
IgorC [24]
36% is the answer to your question.
7 0
3 years ago
Someone gave me flashcards on a keychan. I have to memorize them and then give them back. Can I back them up to my PC by creatin
butalik [34]

Answer: Yup!

If you'd rather take a picture with your phone, just back transfer the photos into your computer if necessary.

5 0
3 years ago
What are good reasons to do yearly disaster recovery testing? check all that apply
AlladinOne [14]

The good reasons to do yearly disaster recovery testing are:

  • To be prepared for all possible snags or problems
  • To identify additional vulnerabilities
  • To allow others with the right access to restore operations.

<h3>Why is the plan important?</h3>

The Yearly recovery scenario testing will help pinpoint potential problems. It's easy to miss things. If you discover a potential problem that could lead to data loss during recovery scenario testing, you will have the chance to fix the problem before any data is actually lost.

Restoration procedures should be documented and accessible, so that anyone with the right access can restore operations when needed. If you aren't available, someone will have to restore operations.

Learn more about disaster on:

brainly.com/question/2916834

#SPJ12

5 0
2 years ago
Please I need help.
fredd [130]

Answer:

The answer is the "TO address"

Explanation:

i just took the test and got it right sooooooo

4 0
3 years ago
what type of authentication does the dod require to accesss sensitive data on mobile devices and /or email
nikklg [1K]
Dod required a car to access data gahagsgssgsg
3 0
3 years ago
Read 2 more answers
Other questions:
  • Utilities software and word processing software are both eamples of
    10·1 answer
  • Fullsoft, Inc. is a software development company based in New York City. Fullsoft’s software product development code is kept co
    10·1 answer
  • Advantages of purchasing a software package over developing software in-house include all of the following except ____. Group of
    13·1 answer
  • Ideally an entity identifier is composed of _____ attribute(s).
    11·1 answer
  • Write a program to generate personalized junk mail. The program takes input both from an input file and from the keyboard.The in
    14·1 answer
  • When a block of steel at 90 degrees Celsius is placed in a bucket of water at 30 degrees Celsius, what happens?
    10·1 answer
  • Subana is writing a program which will calculate the mean average of a set of numbers by adding the numbers and dividing the res
    11·2 answers
  • A ________ is a self-contained program that spreads through a computer network by exploiting security holes in the computers con
    9·1 answer
  • fun fact about London(me): when it comes to relationships she becomes clingy to the person shes dating
    10·1 answer
  • Type the correct answer in the box
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!