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
Otrada [13]
3 years ago
15

6.13: Word Count

Computers and Technology
1 answer:
lions [1.4K]3 years ago
3 0

Answer:

import os

def search_file(file_name):

       file_name += '.txt' # The code automatically adds the .txt extension, so the user is expected to just pass in the name of the file without extension

       for _, __, files in os.walk('.'):

               for file in files:

                       if file_name == file:

                               return file

       raise FileNotFoundError('File not found')

file_name = input('Enter the name of the file without extension > ')

file = search_file(file_name)

with open(file) as open_file:

       a = open_file.read()

       a = a.split()

       print('The file {}.txt contain {} words'.format(file_name, len(a)))

Explanation:

The above code is written in Python Programming Language. The first line of code is an import statement that imports the os module which is responsible for operating system's functionality in Python. This module is needed because we will be doing things like file search in the code.

The next thing that was done is that a function called search_file which accepts just a single argument was defined. The purpose of this function is to use the os module imported earlier and search for the existence of the file passed in as the argument. If the file is found, the file is returned else a FileNotFoundError is raised

Immediately after the function, the program expects an input from the user which should be the name of the file without the extension. It is also assumed that the filename passed in is a text file with the .txt extension.

After the program gets the file name from the user via the input function, the function we defined earlier is now called passing the value of the input as the argument to the function.

if file passed in does not exist, the program crashes there with the FileNotFound exception - thanks to the raise FileNotFoundError statement in the function.

However if the file exists, the file is opened and read. The contents of the file is splitted by whitespace. Then we use the Python's len function is use to count the items in the list after the split function is ran.

Finally, we print this to the console using string formatting

You might be interested in
Which toolbar is located next to the office button and contain the commonly used commands​
Andrei [34K]

Answer: Quick Access Toolbar

The Quick Access Toolbar is located to the right of the Microsoft Office Button . It contains commands that are used most often, for example Redo, Undo and Save.

Explanation:

7 0
4 years ago
"Margaret has $3,200 cash after selling off her television, DVD player, and computer. She has debts of $4,800 owing to the follo
serg [7]

Answer: Hyatt's  will be able to collect $1,365

Explanation: Composition Agreement is a kind of agreement reached between a debtor and its creditors. it a kind of agreement whereby the debtor and creditors agree to collect a percentage of their debts to fully settle their debts from the creditor.

For instance Margaret with a cash of $3,200 to settle a debt of $4,800.

In this case Margaret can decide to pay 65% of the total debts to settle the final debts. Here, Hyatt's  will be able to collect $1,365 as full settle of his debt.

5 0
3 years ago
What block cipher mode of operation uses the most basic approach where the plaintext is divided into blocks, and each block is t
Orlov [11]

Answer:

Electronic Code Book

Explanation:

5 0
3 years ago
For editing youtube videos, what is the best software to use?
Stels [109]
What type of editing ?

7 0
4 years ago
Read 2 more answers
Match each word to its correct meaning.
monitta

Answer:

1. Graphics.

2. Clip art.

Explanation:

1. Graphics: visual representations of information that are not text-images, photos, symbols, diagrams, and so on. Some examples of software applications used for graphics design are CorelDraw, Adobe Illustrator, Affinity Designer, Inkscape, Adobe Photoshop, etc.

Adobe Photoshop is a proprietary software application designed and developed by Adobe inc. for both Windows and MacOS operating system. It is a raster graphics editor that's typically used for imaging and graphics design. It comprises of various shape tools such as ellipse, line, polygon, triangle, custom shape and rectangle.

2. Clip art: digital artwork such as symbols and pictures that can be imported for use in documents or other software applications.

7 0
3 years ago
Other questions:
  • All phones must have a way of making and then terminating a connection to the phone network; however the exact procedure for doi
    6·1 answer
  • In many cases, a subquery can be restated as a/an ______________.
    13·1 answer
  • Individuals and businesses have concerns about data security while using Internet-based applications. Which security risk refers
    13·1 answer
  • If you decide to get married, a trade-off would be that you have to give up being single.
    12·2 answers
  • After an entry in the medical record has been written or keyed and an error is discovered, what procedure should be followed to
    7·1 answer
  • Which type of development metrics does Instagram most improve when it releases an update in the App Store to fix errors its cust
    15·1 answer
  • In one to two sentences, describe how you would insert a row in a spreadsheet.
    5·2 answers
  • In critical thinking, an argument is:
    12·2 answers
  • help this poped up on my pc im on my laptop what does it mean HELP rC % M i \g e - A u t o M e r g e d - b a s e ~ 3 1 b f 3 8 5
    11·2 answers
  • The CIBER network provides a link between the human resource and technology needs of a company with the research capacities and
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!