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
In the event you get pulled over for a traffic stop, describe the situation from the police officer's perspective and list at le
Zepler [3.9K]

Answer:

Dealing with traffic related issues

Explanation:

The police officer are primarily charged with the primary responsibilities of maintaining law and order in any given society.

from the police officer's perspective when I get pulled for a traffic stop it is expected that

  • as a first rule is to always be polite to the officer.  Greet the officer with a warm and friendly smile as this will lower his or her fears.
  • Always follow instructions and give the officer your license, registration and insurance information when they ask for it.  
  • Treat the officer with respect and courtesy.
  • Always remove your sunglasses and maintain eye contact with the officer.   Most law enforcement officials view this as a sign that you are being truthful.
  • Remain as inconspicuous as possible.   If the officer doesn’t remember certain aspects of the incident, this can work to your advantage in court.

The additional two (2) things you need to do make traffic stop go smoothly are:

1) Ensure you maintain a high sense of dutifulness in cause of performing your responsibility,

2) Ensure you put on a user friendly welcome to the road users this help to make them feel safe and secured.

5 0
3 years ago
Read 2 more answers
You support Richman Investments, a brokerage firm that employs 20 brokers. Each broker has his own client computer, and the firm
PSYCHO15rus [73]

Answer:

Test Windows update on one computer first.

Explanation:

To ensure that there are no usability issues, the Windows update services should be tested on one computer. This move is to check for any usability issues before the update is deployed to other computers. As soon as the usability is tested and confirmed on one computer after the update, the Windows update services can be used to deploy the updates to other computers.

4 0
3 years ago
Which type of memory helps in reading as well as writing data?
Anuta_ua [19.1K]

The read-write type of memory helps in reading as well as writing data. This computer memory is used by users to continually update the data (to access (read from) or alter (write to) ) that is held on hardware storage devices. Internal or external hard disk drives, rewritable CDs or small flash drives can be all physical setups of read-write memory.

6 0
3 years ago
Liam noticed someone had accessed his social media account and made several posts without his knowledge. Which of the following
jok3333 [9.3K]

Answer:

Liam could

1) Change the password

Be sure to change the password to a "strong" one (containing lots of characters, numbers, symbols) so that way the password would be difficult to guess.

2) Avoid logging onto social media on public computers or WiFi connections.

Using public WiFi leaves you vulnerable to someone accessing your information through Internet traffic. If you do use public computers, just make sure to log out.

3) Avoid giving out account information to friends and avoid opening suspicious links and emails.

Opening suspicious links or emails could allow malware to infect your computer the moment you open them. Friends can unknowingly share these links that are designed to steal information.

I hope this helped <3 please lmk if there's anything more to add.

4 0
3 years ago
Speech about society being normal
Kisachek [45]

Answer:

Do you know what is best about America? It’s really the fact that the right to equality has been ensured at the maximum level, and for all. And the citizens respect their family and this is being showcased proudly by Sir Donald Trump who not only looks after the whole US without ever hesitating no matter whatever might be the issue and at the same time also look after his great and proven proud family. And that explains in itself why America is so great. And this is a perfect specimen of an inordinate democracy, and that is why American Democracy is so fruitful. There is sufficient money, all sorts of resources, the most influential military, and the world's finest technology. And American history can be a petite one, but it is one of the most noticeable histories in the entire world. You will not find such a great history in any other part of the world. And George Washington, the father of the country set such an example that the next various generations of great leaders were able to build such a great America. It is a society where every citizen enjoys equal rights, and a day before Sir Trump issued various prisoners with graduate degrees, to help them to return to the mainstream of life. No other society in the whole world enjoys such a level of privileges on behalf of equality. And that’s why the US society can be termed as the most normal in the whole world.

Explanation:

Please check the answer section. And I have chosen US as it is the most fruitful democracy of the world. And I feel all the counrtries from the entire world, should learn a lesson from the short history of United States. This is the way in which we can sight a normal society.

3 0
3 years ago
Other questions:
  • Harry is creating a presentation for a school event. He has to deliver the presentation to a huge audience. What should he keep
    14·2 answers
  • What formatting option is easiest to read when printed out
    12·1 answer
  • How is typing speed measured
    12·2 answers
  • In controlling network traffic to minimize slow-downs, a technology called ________ is used to examine data files and sort low-p
    15·1 answer
  • The picture that graphically represents the items you use in Windows is called a/an
    11·1 answer
  • 2.27 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as
    14·2 answers
  • Our readings so far explored computer hardware and software, in particular operating systems and application software. There are
    11·1 answer
  • To implement a small database, a database designer must know the "1" and the "M" sides of each relationship and whether the rela
    13·1 answer
  • Features of Python are *
    9·1 answer
  • Simple Java programming
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!