Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

Outline the steps involved in developing a cash budget.

Answered: 1 week ago