Computers and Technology

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()

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 01:00, EhHannuh6865
Let r be a robotic arm with a fixed base and seven links. the last joint of r is a prismatic joint, the other ones are revolute joints. give a set of parameters that determines a placement of r. what is the dimension of the configuration space resulting from your choice of parameters?
Answers: 3
image
Computers and Technology, 23.06.2019 09:30, rowdycar313p0ao5k
[java] create an application called registrar that has the following classes: a. a student class that minimally stores the following data fields for a student: - name - student id number - number of credits - total grade points earned and this class should also be provides the following methods: - a constructor that initializes the name and id fields - a method that returns the student name field - a method that returns the student id field - methods to set and retrieve the total number of credits - methods to set and retrieve the total number of grade points earned. - a method that returns the gpa (grade points divided by credits) b. an instructor class that minimally stores the following data fields for an instructor: - name - faculty id number - department the following methods should be provided: - a constructor that initializes the name and id fields - methods to set and retrieve the instructor’s department. c. a course class that minimally stores the following data for a course: - name of the course- course registration code- maximum number of 35 students- instructor- number of students- students registered in the course (an array)the following methods should also be provided: - a constructor that initializes the name, registration code, and maximum number of students- methods to set and retrieve the instructor- a method to search for a student in the course; the search should be based on an id number.- a method to add a student to the course. if the course is hill, then an exception with an appropriate message should be raised (try creating your own exception class for this). also, be sure that the student is not already registered in the course. the list of students should be in the order that they registered.- a method to remove a student from the course. if the student is not found, then an exception with an appropriate message should be raised (use the same exception class mentioned a method that will allow course objects to be output to a file using object serialization- a method that will allow course objects to be read in from a file created with object serializationyou will note that the student and instructor classes described above have some commonality. create aperson class that captures this commonality and uses it as a base class for student and instructor. this class should be responsible for the name and id fields and also provide atostring method that returns a string of the form name, id. this will be the inheritedtostring method for the student and instructor classes.1. draw a uml diagram for diss application.2. implement the previous classes in java. write a main program that can serve as a test class that tests all of the methods created and demonstrates that they are working
Answers: 2
image
Computers and Technology, 23.06.2019 11:00, la200564
How should you specify box sizes on a web page if you want the boxes to vary according to the font size of the text they contain? a. in pixels b. in inches c. as percentages d. in em units
Answers: 2
image
Computers and Technology, 24.06.2019 13:00, giulissaf
Append and make table queries are called queries. select complex simple action i think action
Answers: 1
Do you know the correct 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, 19.03.2021 22:40
Konu
Mathematics, 19.03.2021 22:40
Konu
Mathematics, 19.03.2021 22:40