Question: Can you help fix my code? it does not work in its current state ` ` ` squaredef capitalize _ only _ first _

Can you help fix my code? it does not work in its current state
```
\squaredef capitalize_only_first_letter(wrd):
| return wrd[0].upper()+wrd[1].lower() #converts the words in file so only first letter of each one is capatalized
|with open('nws_alert_uc.txt','r')as data_file:
with open('new_nws_alert_uc.txt','a') as output_file:
!
for line in data_file:
word_list = line.split() #splits it too individual words
word_list =[capitalize_only_first_letter(word) for word in word_list]
output_file.write("".join(word_list)+"
")
```
This assignment will let you exercise some file and text handling skills. You'll read in text from a file, line by
line, do some work on the string in that line, and then write out a new file with the modified strings.
The National Weather Service (NWS) publishes alerts when there is the likelihood of dangerous weather.
These alerts are published in plain text, usually in all upper case letters. Some applications (like Storm
Radar from the Weather Channel) show these alerts in all lower case except the first letter of every word is
upper case.
For example, a line from an alert:
PEAK WIND FORECAST: 25-35 MPH WITH GUSTS TO 50 MPH
might appear as:
Peak Wind Forecast: 25-35 Mph With Gusts To 50 Mph
Your job is to read in a data file containing an alert from the NWS (in a file provided on D2L: nws_alert.txt)^(1)
and re-write it to a new file where all the text is lower case except the first letter of each word.
Can you help fix my code? it does not work in its

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!