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
jek_recluse [69]
3 years ago
7

[Files, for loops, exceptions; 20pt] Using a for loop, write a function called countWord(). It takes 2 parameters: The name of a

text file (e.g. gettysburg.txt that is included with this test) and a word to be searched within that file. Your code should return the number of times the given word appears in the file. Capitalization should not matter. Make certain to handle file exceptions gracefully.
Computers and Technology
1 answer:
Sergeu [11.5K]3 years ago
6 0

def countWord(name, word):

   try:

       f = open(name, "r")

       lst = ([])

       w = ""

       for x in f.readlines():

           w += x.lower()

       lst = w.split()

       f.close()

       return lst.count(word)

   except FileNotFoundError:

       print("Please create a file or use the name of an existing text file.")

print("Your word appears", countWord("gettysburg.txt", "random"), "time(s)")

The text file I used for testing looks like:

random words

random words

I'm putting random words in here

random

this is random

RaNdOm

I didn't really know what exceptions your professor is looking for so I just used the file not found one. Best of luck.

You might be interested in
3. How has air - conditioning affected human life?​
meriva

Answer:

Sudden changes in temperature and humidity affect the respiratory system. ... The air circulation can transmit infectious respiratory diseases. Airborne dust and fungi can cause allergic reactions. Air conditioning is associated with chronic rhinitis and pharyngitis, throat irritation and hoarseness.

6 0
3 years ago
A technician is installing a server using a two-channel RAID controller, using RAID1 for the first channel and RAID5 for the sec
Stolb23 [73]

Answer:

Two disks RAID 1 and four disks RAID 5.

Explanation:

The RAID level stands for Redundancy array of independent disk drive level. It is a process whereby disk storage like hard disk drive or solid state disk are connected in array to function in parallel to each other, to promote performance and reliability. The categories of raid level are 0, 1, 3, 5, 10 etc.

The RAID level 1 writes data on both main disk and mirror disk. It is more efficient with only two disk. The RAID 5 strips data across disk array and stores a parity check on them. It can hold 16 disks efficient and can be used in the two channel RAID to hold the remaining four disks.

5 0
3 years ago
Use humorous and monster in a sentence.
Sphinxa [80]

Answer: Here are a few...

1) The monstrous elephant trampled through the jungle crushing everything in its path.

2) Because it was so monstrous, the maid often got lost in the massive home she cleaned.

3) Monstrous amounts of foods are needed to feed the hundreds of refugees who showed up at the soup kitchen.

Explanation:

I hope this helps :D

4 0
3 years ago
Which privacy protection uses four colors to indicate the expected sharing limitations that are to be applied by recipients of t
levacccp [35]

The Traffic Light Protocol (TLP) was created in order to facilitate greater sharing of information. TLP is a set of designations used to ensure that sensitive information is shared with the appropriate audience. It employs four colors to indicate expected sharing boundaries to be applied by the recipient(s).

cisagov

3 0
3 years ago
One hallmark of good strategic design is supporting a variety of gameplay styles and different ways to achieve victory.
Nonamiya [84]
It creates the illusion of creating a original path, so its true
3 0
4 years ago
Other questions:
  • What is the definition of online communication
    15·1 answer
  • Which of the following is least likely checked by the comprehensive component monitor?
    7·1 answer
  • 5. The hazardous component in most antifreeze is _____, which is extremely toxic to humans and animals. A) Calcium Carbonate B)
    13·2 answers
  • Can a msi b450 tomahawk motherboard fit into a darkflash dlm21 mesh micro atx tower
    13·1 answer
  • answer for brainliest Today, trending current events are often present on websites. Which of the following early developments in
    15·1 answer
  • How do you make computers or microwaves?
    13·1 answer
  • The Scratch blocks are organized into 9 color-coded categories. Select all that apply.
    8·1 answer
  • What are the qualitative data items about text book​
    12·1 answer
  • How can e-group help in collaborating online​
    5·1 answer
  • After a Hacker has selects her target, performed reconnaissance on the potential target's network, and probed active Internet Ad
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!