Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have a question. I have a txt file save on my computer and I have a python program that supposed to edit the txt
I have a question. I have a txt file save on my computer and I have a python program that supposed to edit the txt file to arrange the information in a table. The program runs, but when reopen the txt file, no changes made to it. I can't figure out what I am missing from the python program to make the changes to the txt file.
Here is the python program:
f=open("CityStateData.txt", "r") for c in f: # extract the city name from the element of the list cityname = c.split(",")[0].strip() # after extracting the city name, extract the state # the state code is two characters long # strip is ued to remove leading and trailing white spaces state = (c.split(",")[1]).strip()[0:2].strip() # extract the zip code from the element. It is the last token # of the given element zipcode = (c.split(",")[1]).strip()[2:].strip() # display the result in tabular form using the format # function of the str class print("{0:19} {1:2} {2:5}".format(cityname, state, zipcode)) f.close()
Advise please!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started