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
Remember that kid who would always ask you for your food, even though he packed his own lunch.
Verizon [17]

Answer:

ye ye

Explanation:

7 0
3 years ago
Read 2 more answers
Help me right now!!!!!!!!!!!!!!!!!!!!!!!!11
PilotLPTM [1.2K]
Word-processing software includes basic applications designed for casual business or home users and powerful, advanced applications capable of meeting the most-demanding needs of businesses. Many word-processing applications are designed for use as part of a suite or integrated group of word-processing, spreadsheet, and presentation programs
4 0
3 years ago
A data type consisting of numbers, letters and symbols is a _____.
LekaFEV [45]

Answer:

That's the answer

Hope it helps

#brainliest

#heart

#star

#Carryonlearning

4 0
2 years ago
java class What is the output of the following JAVA program (Java assumes public if no access modifier is given)? class Test { p
Natasha2012 [34]

Answer:

The answer to the given question is it will produce an "error"  

Explanation:

In the given java program it will produce an error because in java we do not use double quote("""") for message printing. We use a single quote("") for message printing. In the given program if we use a single quote(""). so it will give output that is "dogood:dogood".

The correct program to this question is can be given as:

Program:

public class Test  //define a class test.

{

   public static void main(String[] args)  //define main method

   {

       Test obj = new Test();   //create class object  

       obj.start(); //calling function

   }  

   void start()  //define function start.  

   {

       String stra = "do";   //define variable and assign value.

       String strb = method(stra);  //define variable and pass stra variable in method() function as a parameter.

       System.out.print(":"+stra + strb); //print value.  

   }

   String method(String stra)  //define function method  

   {  

       stra = stra + "good";   //add value

       System.out.print(stra);  //print value of stra

       return"good";  //return value

   }

}

Output:

dogood:dogood

6 0
3 years ago
Assume that the int variables i and j have been declared, and that n has been declared and initialized.
timama [110]

Answer:

public class num6 {

   public static void main(String[] args) {

       int n = 4;

       for(int i = 1; i <= n; ++i) {

           for(int j = 1; j <= i; ++j) {

               System.out.print("* ");

           }

           System.out.println();

       }

   }

}

Explanation:

This solution is implemented in Java

Two for loops are required for this (an inner nd outer for loop).

The innner and outer for loops can be seen as implementing rows and columns (so on the first 'row' i=1, so a single star is printed, on the second row, i =2, two stars are printed and so on, all on seperate lines)

8 0
3 years ago
Other questions:
  • Create a funtion makeStudent(studentlist) where studentlist is your list of Student namedtuples The function should do the follo
    13·1 answer
  • If you want to use your computer for recording your band, you would benefit most from a(n)
    13·2 answers
  • Write a definition of the function printDottedLine, which has no parameters and doesn't return anything. The function prints to
    14·1 answer
  • The first step when entering data is _
    6·1 answer
  • Which of the following statements are true concerning abstraction and refinement? Select 3 options:
    14·1 answer
  • What is the difference between second generation and third generation​
    15·1 answer
  • How am i able to hear a presenter from a radio station through my fm tuner​
    14·1 answer
  • What is the two’s compliment of -95,-122,-111,-57
    9·1 answer
  • Discuss the advantages of using analogue multi-tester or digital multi-tester over the other.​
    12·1 answer
  • When you add encryption to a powerpoint presentation what does it do
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!