subject

Your assignment is to take a list of strings representing [city, state, and zip code] and print them in a nice table, one per line. However, the data was input on a keyboard that had a temperamental space bar. Sometimes it doesn't work and other times it generates multiple spaces, so the data may look like

'Rolla, MO 65402'
or

'Springfield, MO65897'
The one thing that is consistent is that there is a comma after the city name, the state is always two upper case characters, and the zip code is 5 adjacent characters 0-9.

Your program needs to find the individual components [city, state, zip] in the string, then print them lined up in columns.

One problem is the length of the city name. A simple way to start is to always make the city name be 15 characters long. Look at the string methods in section 9.5 for how to do this. You may have to look on the web for some additional examples. Here is what your output would look like doing that:

Cape Girardeau MO 63780
Columbia MO 65201
Kansas City MO 64108
Rolla MO 65402
Springfield MO 65897
St Joseph MO 64504
St Louis MO 63111
Ames IA 50010
Enid OK 73773
West Palm Beach FL 33412
International F MN 56649
Frostbite Falls MN 56650
A nicer table would always print out the full city name, not just the first 15 characters, but still line things up nicely. For full credit, make it so that there is exactly one space after the longest city name and the start of the state column, like this:

Enid OK 73773
West Palm Beach FL 33412
International Falls MN 56649
Frostbite Falls MN 56650
Be sure to document your program with an appropriate header comment, including your name, date, and description of what the program does. Also add comments before blocks of code, rather than at the end of a line.

There are two pieces to this assignment, getting slices of one string and printing the pieces in a table.

Since the data in the list is right in front of you, you'll be tempted to count the number of characters in the longest city by hand and hard code that value into your program. That's not going to earn full credit. An easy way to check your program is to get it working with the current data, then delete the line with International Falls and rerun your program. If it still prints the state one space after the longest city, then you figured out a good solution.



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 ','Charlotte, NC 28214', 'Upper Marlboro MD 20774'

]

# Print the table
for c in mycities:
print(c)

main()

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:30, messyquestions
Plz 40 points what are raster vectors? a bitmap image a vector file a type of printing press a small projector
Answers: 1
image
Computers and Technology, 22.06.2019 20:40, broang23
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it
Answers: 2
image
Computers and Technology, 22.06.2019 21:30, sunshinekisses
After you clean an engine with hot water spray, it seems to stall; when it doesn't stall, it's idling noisily. technician a says to check for loose bolts on the flex plate near the torque converter. technician b says to wipe down the spark plug wires and the distributor cap. who is correct? a. technician a b. both technicians a and b c. technician b
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, emmaishere69
List 3 items that were on kens resume that should have been excluded
Answers: 1
You know the right answer?
Your assignment is to take a list of strings representing [city, state, and zip code] and print them...

Questions in other subjects:

Konu
Mathematics, 26.08.2019 08:00
Konu
Computers and Technology, 26.08.2019 08:00
Konu
English, 26.08.2019 08:00