Description
Submit the zipped Python program including at least Project1.py and States.csv. The zip file should be named <your last name>_Project1.zip (for example, Liu_Project1.zip). The program should be well documented including inline comments and docstrings. I give some suggestions for docstrings below. More can be found in PEP-8 (https: //www.python.org/dev/peps/pep-0008/) and PEP-257 (https://www.python. org/dev/peps/pep-0257/).
Requirements:
-
Create a class named State that will store information about a US state and provide methods to get, and set the data, and compare the states.
-
Data attributes: State Name, Capital City, State Abbreviation, State Population, Region, US House Seats
-
-
-
Initializer (__init__)
-
-
-
Getter and setter methods for each field
-
-
-
__gt__ method so that two State objects can be compared based on state names
-
-
-
__str__ method so that a state object can be printed like a string
-
-
Create a program that will:
-
-
Read a file (csv) of states and create a list of state objects containing that data.
-
-
-
Offer the user the following options:
-
-
-
-
Print a state report
-
-
-
-
-
Sort by state name (using Quick Sort)
-
-
-
-
-
Sort by population (using Radix sort)
-
-
-
-
-
Find and print a given state (using binary search if the data is sorted by state name, sequential search if not)
-
-
-
-
-
Quit
-
-
-
-
Implement the given option, then prompt again. (deal with invalid choice)
-
Your program should have functions for options 1-5.
d. The State report in option 1 should be in this form:
State Name Capital City State Abbr State Population Region US House Seats
——————————————————————————————
Florida |
Tallahassee |
FL |
19,552,860 |
South |
27 |
Pennsylvania |
Harrisburg |
PA |
12,773,801 |
Middle Atlantic |
18 |
Massachusetts |
Boston |
MA |
6,692,824 |
New England |
9 |
e. The State report in option 5 should be in this form:
State Name: Florida
Capital City: Tallahassee
State Abbr: FL
State Population: 19,552,860
Region: South
US House Seats: 27
Liu University of North Florida 1
CAP4630/5605 Project 1 – Python Basics
Provide docstring comments:
Comments for a module (must be at the top):
”””
Detailed description of the module.
Author: <your name>
Version: <date you last changed the class>
Email: <your UNF email>
”””
Comments for a function definition (must be the first thing inside the function):
”””
Description of the purpose of the function, the meaning of the input parameters (if any) and the meaning of the return values (if any).
:param parameter description of the parameter (one for each) :return description of the return value
:raise exceptions that may be raised in this function ”””
Comments for a class definition (must be the first thing inside the class)
”””
Detailed description of the class.
”””
Liu University of North Florida 2
CAP4630/5605 Project 1 – Python Basics
Example Ouput:
CAP4640/5605 Project 1
Instructor: Xudong Liu
Enter the file name: States.csv
There were 50 state records read.
-
Print a state report
-
Sort by State name
-
Sort by Population
-
Find and print a given state
-
Quit
Enter your choice: 1
State Name Capital City State Abbr State Population Region US House Seats
——————————————————————————————
Louisiana |
Baton Rouge |
LA |
4,625,470 |
South |
6 |
Wisconsin |
Madison |
WI |
5,742,713 |
Midwest |
8 |
New Mexico |
Santa Fe |
NM |
2,085,287 |
Southwest |
3 |
. . . |
-
Print a state report
-
Sort by State name
-
Sort by Population
-
Find and print a given state
-
Quit
Enter your choice: 3
States sorted by Population.
-
Print a state report
-
Sort by State name
-
Sort by Population
-
Find and print a given state
-
Quit
Enter your choice: 1
State Name Capital City State Abbr State Population Region US House Seats
——————————————————————————————
Wyoming |
Cheyenne |
WY |
582,658 |
West |
1 |
Vermont |
Montpelier |
VT |
626,630 |
New England |
1 |
North Dakota |
Bismarck |
ND |
723,393 |
Midwest |
1 |
. . . |
-
Print a state report
-
Sort by State name
-
Sort by Population
-
Find and print a given state
-
Quit
Enter your choice: 4
Enter the state name: Florida
Liu University of North Florida 3
CAP4630/5605 Project 1 – Python Basics
Sequential search
State Name: Florida
Capital City: Tallahassee
State Abbr: FL
State Population: 19,552,860
Region: South
US House Seats: 27
-
Print a state report
-
Sort by State name
-
Sort by Population
-
Find and print a given state
-
Quit
Enter your choice: 4
Enter the state name: Canada
Sequential search
Error: State Canada not found
-
Print a state report
-
Sort by State name
-
Sort by Population
-
Find and print a given state
-
Quit
Enter your choice: 2
States sorted by State name.
-
Print a state report
-
Sort by State name
-
Sort by Population
-
Find and print a given state
-
Quit
Enter your choice: 1
State Name Capital City State Abbr State Population Region US House Seats
——————————————————————————————
Alabama |
Montgomery |
AL |
4,833,722 |
South |
7 |
Alaska |
Juno |
AK |
735,132 |
West |
1 |
Arizona |
Phoenix |
AZ |
6,626,624 |
Southwest |
9 |
. . . |
-
Print a state report
-
Sort by State name
-
Sort by Population
-
Find and print a given state
-
Quit
Enter your choice: 4
Enter the state name: Kentucky
Liu University of North Florida 4
CAP4630/5605 Project 1 – Python Basics
Binary search
State Name: Kentucky
Capital City: Frankfort
State Abbr: KY
State Population: 4,395,295
Region: South
US House Seats: 6
-
Print a state report
-
Sort by State name
-
Sort by Population
-
Find and print a given state
-
Quit
Enter your choice: 23
Invalid choice enter 1-5: 0
Invalid choice enter 1-5: A
Invalid choice enter 1-5: 5
Have a good day!
Liu University of North Florida 5