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
nancy finds it difficult to locate emails in her inbox . what action should she take to locate a particular type of email instan
Anuta_ua [19.1K]
Well, what Nancy can do is either search for her e-mail and access it or Nancy can restart her device.      :D Hope this helps

8 0
3 years ago
Why people shouldnt get married​
inn [45]
Well it depends if your thinking! I know many reasons why people should get married but I also know many reasons why people shouldn’t get married!

For an example if you are a man and you don’t want to get married, well I think it’s 50% wrong and another 50% right cause if you want to enjoy life and not be stuck with the same wife you wouldn’t get married, but now think of having a family when you get married you receive a blessing, cause you will have son , daughters and a wife who will support you all the time!
3 0
3 years ago
Text that is positioned at the top of a column and labels the<br> column.
Vanyuwa [196]

Answer:

column header

Explanation:

3 0
3 years ago
Automotive engine cylinder heads can be made of what?
pantera1 [17]

Answer:

automotive engine cylinder heads can be made of cast iron or aluminum

6 0
3 years ago
PYTHON CODING LANGUAGE (i am a beginner)
MaRussiya [10]
#let the user input data
Hours = int(input(“enter how many hours were worked”))

Pay_rate = float(input(“Enter the pay rate”))

Pay_amount = Pay_rate * Hours
#calculate the wages


Print (Pay_amount)
#print the final answer
5 0
3 years ago
Other questions:
  • Implement the function maxLoc(), which returns an iterator at the largest element in a list. template typename list::iterator ma
    14·1 answer
  • 100 students were asked to fill out a form with three survey questions, as follows: H: Honor Roll C: Club membership (Robotics C
    7·1 answer
  • Regularly Tuning up a computer can assist keeping it running at Peak speed. True or False?
    12·1 answer
  • What helps companies and organizations to target masses of people, provide 24/7 services, and deliver better marketing in a chea
    6·1 answer
  • Which of the following best describes when a packet is addressed so that more than one destination can receive it and the first
    11·1 answer
  • (a) Define a goal for software product quality and an associated metric for that attribute. (b) Explain how you could show that
    7·1 answer
  • 4.8 Code Practice: Question 1<br> I need help
    13·1 answer
  • What Temperature does mainframe need
    15·2 answers
  • Programs for embedded devices are often written in assembly language. Some embedded processors have limited instructions, like M
    5·1 answer
  • To generate a series of first ten counting number of algorithm​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!