Defining all the data as part of your program

Assignment Help Business Management
Reference no: EM132261384

Please explain and provide example of how do I rewrite a python program as a text file?

Here is my program in Unit 5.

#  List of strings representing city, state zip
#  One space after the longest city name
#  Adds two additional test cases 
#  Information in a nicely formatted table
def main():
    mycities = ['Cape Girardeau, MO 63780','Columbia, MO  65201',
                'Kansas City, MO 64108','Rolla,MO  65402',
                'Springfield, MO65897','St Joseph, MO64504',
                'St Louis,MO63111', 'Ames, IA 50010', 'Enid, OK 73773',
                'West Palm Beach, FL 33412',
                'International Falls, MN 56649', 'Frostbite Falls, MN 56650',
                'Chattahoochee Hills, GA  30268', 'Lava Hot Springs, ID 83246'
                ]

    # Prints table
    for c in mycities:
        #Slice that is the city
        city = c[:c.index(",")]

        #Slice that is the state abbreviation
        state = c[c.index(",") + 1:-5].strip()
        #state = state.strip()

        #Slice that is the area code, last five numbers
        zipcode = c[-5:]

        #Reformmated string using the above stated variables
        formatted_string = "{}{} {}".format(city.ljust(20), state, zipcode)
        #formatted_string = "{:<{}}".format(20, mycities)
        print(formatted_string)

main()

My next assignment is asking to do this:

1.This assignment must be done in a standalone Python environment

2.Download the data file CityStateData.txt. This is the same set of data that you used in the previous assignment, but stored in a text file instead. Put this text file in the same folder as your Python program.

Here is the CityStateData text file:

Cape Girardeau, MO 63780
Columbia, MO  65201
Kansas City, MO 64108
Rolla,MO   65402
Springfield, MO65897
St. Joseph, MO64504
St Louis,MO63111
Ames,   IA 50010
Enid, OK 73773
West Palm Beach, FL 33412
International Falls, MN 56649
Frostbite Falls,MN      56650     
  1. Rewrite your program from Unit 5 so that it reads myCities from a file instead of defining all the data as part of your program itself. 
  2. The file aspect should be the only thing that you change - the rest of the program logic should remain the same.
  3. Add your two test cases from the program in Unit 5 (these are the cities I added).

Chattahoochee Hills, GA  30268', 'Lava Hot Springs, ID 83246

  1. Add two more cities of your own at the end of the text file. 
  2. You can edit the text file with Notepad, or IDLE, or any text editor on your system.

Reference no: EM132261384

Questions Cloud

Displays a table of the centigrade temperatures : Design a program that displays a table of the centigrade temperatures 0 through 20 and their Fahrenheit equivalents.
Common requirement gathering technique : What is the most common requirement gathering technique in the analysis stage of an SDLC?
Calculate the total attendance for the years : In cell B16, enter a function to calculate the total attendance for the years 2014 through 2018 using the totals in the range B12:F12.
Select a common attack-describe the attack : Research current news for attacks for the example you have provided.
Defining all the data as part of your program : This is the same set of data that you used in the previous assignment, but stored in a text file instead. Put this text file in the same folder as your Python
Algorithm to decide if an input edge : You are given a weighted graph G = (V,E) with positive weights, c(i) for all i in E. Give a linear time (O(|E| + |V|)) algorithm to decide if an input edge e =
List 5 different tools to get credentials : 1. List out 5 adverse effects of a Bad password used in an online web application?
Investigations and forensics analysis for a company : You have been hired to perform computer investigations and forensics analysis for a company.
Are some computer systems considered services : Are some computer systems considered services even though they are not web based?

Reviews

Write a Review

Business Management Questions & Answers

  Explain how the situation would be different

Next, imagine yourself as a practitioner of servant leadership. You have been appointed into the leadership role in this same circumstance. Explain how the situation would be different.

  E-business to overall supply chain performance

How does e-business support an organization's global SCM initiatives? Do e-business activities increase or decrease the return on investment of an organization?

  Consider the various training and development formats

Consider the various training and development formats described in chapter 8. Which three do you think would be most effective for developing the skills

  Explain the ethical implications of health care

Explain the ethical implications of health care research relating to Patient DNA for research without the patient's knowledge or consent.

  How much is the restaurant contributing to covering the cost

A restaurant sells Pizza at a rate of $10/slice. Expenses for restaurant include raw material for pizza at $5 per slice. $100 as monthly insurance.

  Identify three weaknesses that you possess

Identify three weaknesses that you possess. Provide specific examples of how you could improve each of these weaknesses in order to make yourself a more well-rounded manager.

  When would one be preferred over the other

The two types of diversification are Related & Unrelated Diversity. When would one be preferred over the other?

  Describe some key models of training

Describe some key models of training. Which do you think is most effective?

  Determining the native american traditions

Threads Main View Indigenous religions, such as those of Native American traditions, claim a special relationship with nature. The concept of sacred space is particularly important. What makes a sacred place? Can you name some? Are there any s..

  Write a white paper on media and community as stakeholders

Write a white paper on Media and Community as Stakeholders. There is no length requirement for the individual white paper; it is totally up to you to cover.

  Monitoring and reporting

Dr. Salkind from Valley Healthcare asks you to continue the good work you have done for the organization.  You briefly tell him about the importance of continuously monitoring, testing, and improving countermeasures.

  Eliminate abuse of power and corruption

What can be done to prevent or eliminate abuse of power and corruption?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd