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 capitalizeonlyfirstletterwrd:
return wrdupperwrdlower #converts the words in file so only first letter of each one is capatalized
with opennwsalertuctxtras datafile:
with opennewnwsalertuctxta as outputfile:
for line in datafile:
wordlist line.split #splits it too individual words
wordlist capitalizeonlyfirstletterword for word in wordlist
outputfile.writejoinwordlist
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: MPH WITH GUSTS TO MPH
might appear as:
Peak Wind Forecast: Mph With Gusts To Mph
Your job is to read in a data file containing an alert from the NWS in a file provided on DL: nwsalert.txt
and rewrite it to a new file where all the text is lower case except the first letter of each word.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
