Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IT-209 - Assignment 1 (A1) Reviewing and Exercising Python Capabilities IT209 Lab Assignment 1 (LA1) Assignment Given: Lab #1, 01/31/2023 Lab Assignment Due: end of

IT-209 - Assignment 1 (A1) Reviewing and Exercising Python Capabilities IT209 Lab Assignment 1 (LA1) Assignment Given: Lab #1, 01/31/2023 Lab Assignment Due: end of Lab or at the discretion of the GTA Complete Class Assignment (A1) Due: 02/09/2022, 11:59 pm This assignment serves as a review of several important Python features and capabilities you learned in the previous course. In it you will create code to do the following (parentheses indicate which part of the assignment is due in Lab 1, LA1, and which is due later as part of the class assignment A1): 1. read a file of U.S. state information from a text file (LA1) 2. create a Python two dimensional list, or list-of-lists, from the info in the file (LA1) 3. display each item in the list (LA1) 4. build a dictionary from the state list consisting of the state abbreviation as key, and a list of [state name, state capital, and state population] as the associated item (A1) 5. create an output text file and write each state item to from the dictionary by iterating through the it and writing the state name, capital, and population in comma-separated format, with each state being on its own separate line (A1) Note that the above are to be implemented as separate functions. The file read and list create, items 1 and 2, should be implemented as one function, but items 3, 4, and 5 should each be implemented as a function, resulting in a total of four that you are to create. This lab assignment requires you to complete items 1, 2, and 3 above by creating two functions, and is worth a total of up to 10 points. Items 4 and 5 are to be completed as part of Assignment #1 (A1) by creating the other two required functions, and is worth up to 20 points. So this assignment counts for both the first lab and the first part of the first programming assignment. Use the time in the lab to help complete part of it. Input File You will be provided with an input file consisting of U.S. state information. The file name is stateinfo7.txt. Each line consists of items separated by a semi-colon (;): state abbreviation, full state name, state capital, and state population. All of these will be read in as string types and dont need to be converted. Part of the input file is shown below. The actual file has additional lines. AL; Alabama; Montgomery; 4447100 AK; Alaska; Juneau; 626932 AZ; Arizona; Phoenix; 5130632 AR; Arkansas; Little Rock; 2673400 CA; California; Sacramento; 33871648 CO; Colorado; Denver; 4301261 CT; Connecticut; Hartford; 3405565 DE; Delaware; Dover; 783600 DC; District of Columbia; Washington; 572059 FL; Florida; Tallahassee; 15982378 GA; Georgia; Atlanta; 8186453 Functions The separate functions to be implemented should be such that the global code is minimized. With most of the programs action being handled by the functions the global code could be approximately this small: # Lab 1 (LA1) code stateList = loadItems() # invoke function to read the file into a list, return the stateList displayItems(stateList) # takes list as input and prints it (this should be simple) # Assignment #1 (A1) code SD = buildDict(stateList) # builds and returns the dictionary SD built from the stateList writeFile(SD) # creates output file and writes SD records to it The above shows suggested function names, but you may create your own. The Lab requires you to create loadItems and displayItems. loadItems reads the input file, splits items on each line into their own strings, places those items in a list, then appends that to a master list. The result is a list of lists, or two dimensional list, and is returned and saved in stateList above. The stateList list of lists (or 2 dimensional list) will therefore look like this: [ ['AL, Alabama, Montgomery, 4447100], [AK, Alaska, Juneau, 626932], [AZ, Arizona, Phoenix, 5130632], . . . [WY, Wyoming, Cheyenne, 483782] ] Cleaning the Input Data When reading the state data from the input file be sure to: 1. Only add lines that have actual data sometimes there are blank lines, especially at the end of the file, often just extra newline ( ) characters. To do this check the length of each input line. If the line length is greater than 4, you may assume it has actual data. 2. Split the data into its own parts using the split() method: abbreviation, name, capital, population using split and a semi-colon (;) as the separator 3. Remove extraneous blanks from the start and end of each data item using the strip() method 4. Remove the newline character from the end of the input line Displaying the Input Data displayItems(stateList) iterates through the list parameter and prints out each item on a separate line. The string format method is used to produce neat uniform columns. The output should look like this: Abbrev.# Name Capital Population ======== ====================== ================== ======== AL Alabama Montgomery 4447100 AK Alaska Juneau 626932 (etc.) Doing the above fulfills the Lab 1 requirement. The following is required to complete Programming Assignment #1 (A1). Dictionary The buildDict() function reads each inventory item from the stateList list and builds a dictionary consisting of the state abbreviation as the key, which is the first item in each states list. The associated value is a list consisting of the state name, capital, and population. For example, the dictionary item for Alabama would be: {AL: [Alabama, Montgomery, 4447100] } The function returns SD, the complete dictionary, which will have one entry like the above for each state. Output File The output file is a text file consisting of comma-separated data. The file name you create is IT209_A1output.txt. There is one line per data item. Each line consists of (1) state name, (2) state capital, and (3) population. Build the file by iterating through the dictionary, which is supplied as a parameter to the function, and writing one line with the individual items on it, separated by a comma. Do not write the list itself to the file. Sample output file lines are show below as they would appear when viewing using Notepad: Alabama,Montgomery,444710 Alaska,Juneau,62693 Arizona,Phoenix,513063 Arkansas,Little Rock,267340 California,Sacramento,3387164 Colorado,Denver,430126 Connecticut,Hartford,340556 Delaware,Dover,78360 District of Columbia,Washington,57205 Florida,Tallahassee,1598237 (etc.) What and where to submit: 1. Submit by uploading two files: the python file containing the Python code, and the screenshot of output (only for LA1) or the output text file you generate (only for A1), to Blackboard. 2. For the lab portion, name the submitted file: __LA1.py. For example: mary_smith_LA1.py. 3. For the class assignment portion, name the file: __A1,py. 4. For both, include a short set of comments as the first lines that identify the program, its purpose, and its author. How the assignment will be assessed The Python code will be visually inspected and executed via command line (python .py) or double-clicking it from a Directory. The GTA will run it with a sample input file and verify correct execution, including creation of the output file. For the Lab portion was previously submitted and graded separately. For this portion, the GTA will execute all functions and verify that the correct display output and output file is produced. For the class assignment the following 20 point scale will be used: Item Assessment Description Max Value 1 .Python code (LA1) A complete program is submitted, is named correctly, has the required functions, and includes identifying comments 2 2. read, create list (LA1) Read the file of state input and create the list (from Lab 1) 4 3. display list (LA1) Neatly display the stateList items (from Lab 1) 4 4. create dictionary (A1) Create the dictionary abbrev. is the key, values are a list consisting of a list of [state name, capital, population] 6 5. create output file (A1) Correct execution: Create output file per the assignment specification 6 Total 20 Note: Lab 1 (LA1) consists of items 1 3, above, and is worth up to 10 points. Assignment #1 (A1) consists of all the above items and is worth up to 20 points Correctly completing LA1 and A1 on time is therefore worth up to 30 points (10 + 20). NEED ASAP

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_2

Step: 3

blur-text-image_3

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

8. Why is a bus protocol important?

Answered: 1 week ago