python-ITP 115 2022

ITP 115 2022-01-04 Page 1 of 21 Final Project Learning Objective Demonstrate knowledge of Python programming concepts learned throughout the semester. You are not allowed to use Python concepts that were not taught this semester in this course. Assignment Description Write a program that allows the user to learn about the national parks. Read in a CSV file with information about national parks to create a list of dictionary objects. Each dictionary object holds the information for one national park. The user will be allowed to get information regarding the national parks. You are provided a CSV with data about the national parks. Each row represents one line in a table, and commas separate each column. The first line in the CSV file represents the header which contains the keys for the dictionary objects. Each subsequent row represents a park. CSV File (Example) Code,Name,State,Acres,Latitude,Longitude,Date,Description ACAD,Acadia National Park,ME,47390,44.35,-68.21,1919-02-26,”…” ARCH,Arches National Park,UT,76519,38.68,-109.57,1971-11-12,”…” ZION,Zion National Park,UT,146598,37.3,-113.05,1919-11-19,”…” CSV Data in a Table (Example) Code Name State Acres Latitude Longitude Date Description ACAD Acadia National Park ME 47390 44.35 -68.21 1919-2-26 Covering most of Mount … ARCH Arches National Park UT 76519 38.68 -109.57 1971-11-12 This site features more … ZION Zion National Park UT 146598 37.3 -113.05 1919-11-19 Located at the junction of the … ITP 115 2022-01-04 Page 2 of 21 Your solution must use techniques from course materials. You may NOT import and use the CSV or other modules to process the CSV file. Steps 1. In PyCharm (Community Edition), open an existing project (such as ITP115) or create a new project. o If you open an existing project, then create a new directory (probably under the Assignments directory) named project_last_first where last is your last/family name and first is your preferred first name. Use all lower case letters. o If you create a new project, then name it project_last_first where last is your last/family name and first is your preferred first name. Use all lower case letters. 2. In the project or directory, you will create multiple Python files. At the top of each file, put comments in the following format and replace the name, email, section, and filename with your actual information: # Name, USC email # ITP 115, Spring 2022 # Section: number or nickname # Final Project # filename.py # Description: # Describe what this file does. 3. Put the national_parks.csv file in your project_last_first directory. o Download the file from Blackboard under the item for the Final Project. o Drag it onto your project_last_first directory in PyCharm. 4. Create a Python file entitled tasks.py. In this file, you will define functions that will be called from other functions in another Python file. o Define the readParksFile() function. Parameter: fileName is the name of the CSV file to read and it has a default value of “national_parks.csv” Return value: a list of dictionary objects where the keys are the strings from the header row and the values are the information from the rest of the CSV file ITP 115 2022-01-04 Page 3 of 21 Each park is represented with a dictionary. The keys are the words from the header row, which are the following strings: “Code”, “Name”, “State”, “Acres”, “Latitude”, “Longitude”, “Date”, and “Description”. The remaining rows of the CSV file have information for a park. You will notice that the description string for a park may contain a comma. The description for a park can contain the string up to the first comma. If you want to include the entire description, then you will need to use slicing and the str.join() function. o Define the convertDate() function. Parameter: dataStr is a string containing the date (YYYY-MM-DD) Return value: a string with the date in the following format: Month Day, Year For example, let’s say dataStr contains the value “1919-02-26”. Return the string “February 26, 1919”. Create any variables you need such as a list of month names. o Define the getLargestPark() function. Parameter: parksList is a list of the parks where each park is a dictionary Return value: a string that is the park code of the park with the largest area Determine the largest park by using the value of the “Acres” key in the dictionary for each park. If the value was set as a string, then convert to an integer. To get the park code, use the “Code” key in the dictionary for each park. 5. Create a Python file entitled interface.py. In this file, you will define functions that will be called from other functions in another Python file. o Import the tasks file in order for the main() function in this file to be able to call functions in the tasks.py file that you have defined. o Create the getMenuDict() function. Parameters: None Return value: a dictionary where the keys are letters for the user to input and the values are descriptions of the menu options. The keys are the following letters: “A”, “B”, “C”, “D”, and “Q”. ITP 115 2022-01-04 Page 4 of 21 The corresponding values are the following strings: “All national parks”, “Parks in a particular state”, “The largest park”, “Search for a park”, and “Quit”. o Create the displayMenu() function. Parameter: menuDict is a dictionary for the menu Return value: None Print the menu to the user using the menuDict parameter. The menu should look like the following: A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park Q -> Quit o Create the getUserChoice() function. Parameter: menuDict is a dictionary for the menu Return value: a string that is a valid choice entered by the user Get input from the user using the following prompt: Choice: a Use the appropriate loop to continue to ask the user for input until they enter valid input. Allow the user to enter in upper or lower case. The keys in the menuDict parameter have the valid letters. Choice: 1 Choice: x Choice: q Make sure to return an uppercase string. o Create the printAllParks() function. Parameter: parksList is a list of the parks where each park is a dictionary Return value: None Loop through the list and print some information for each park in the following format: ITP 115 2022-01-04 Page 5 of 21 Name (Code) Location: State Area: Acres acres Date Established: Month Day, Year Here is an example with the first and last park: Acadia National Park (ACAD) Location: ME Area: 47390 acres Date Established: February 26, 1919 Zion National Park (ZION) Location: UT Area: 146598 acres Date Established: November 19, 1919 To print the date, use the tasks.convertDate() function. You may want to create a function to print one park where the parameter is a dictionary object for a park. o Create the getStateAbbr() function. Parameters: None Return value: a string with a two-letter abbreviation of a state Get input from the user for a state. Allow the user to enter upper or lower case. Here is an example: Enter a state: ca Use an appropriate loop to continue to ask the user for input until they enter a string that only has two characters. Here is an example: Enter a state: calif Need the two letter abbreviation Enter a state: cal Need the two letter abbreviation Enter a state: ca You do not need to guarantee that the state is a valid state. Return the two-letter abbreviation of a state in upper case. o Define the printParksInState() function. ITP 115 2022-01-04 Page 6 of 21 Parameter: parksList is a list containing parks which are each represented with a dictionary object Return value: None Call the getStateAbbr() function to get a state. Loop through the parks using the parksList parameter. Check to see if the state entered by the user is in park using the “State” key. If so, then print some information for each park in the following format: Name (Code) Location: State Area: Acres acres Date Established: Month Day, Year If there are no parks in the state, then print a message stating that there are no national parks in that state or that it is not a valid state. Here is an example: There are no national parks in AA or it is not a valid state. o Define the printLargestPark() function. Parameter: parksList is a list containing parks which are each represented with a dictionary object Return value: None Call the tasks.getLargestPark() function to get the code of the largest park. Print information about the park including the description in the following format: Name (Code) Location: State Area: Acres acres Date Established: Month Day, Year Description: Description Here is an example: Wrangell – St Elias National Park and Preserve (WRST) Location: AK Area: 8323148 acres Date Established: December 02, 1980 Description: The largest national park in the system protects … ITP 115 2022-01-04 Page 7 of 21 o Define the printParksForSearch() function. Parameter: parksList is a list containing parks which are each represented with a dictionary object Return value: None Get a search term from the user. Here is an example: Enter text for searching: cave Loop thru the list of parks and check to see if the search text is in the park’s Code, Name, or Description. A park should be printed even if the search text is a different case than in the park’s information. Print information about the park including the description in the following format: Name (Code) Location: State Area: Acres acres Date Established: Month Day, Year Description: Description Here is one park that is printed when the search text is ‘cave’: Carlsbad Caverns National Park (CAVE) Location: NM Area: 46766 acres Date Established: May 14, 1930 Description: Carlsbad Caverns has 117 caves If there are no parks in the state, then print a message stating that there are no national parks for the search text. Here is an example: There are no national parks for the search text of ‘koala’. 6. Create a Python file entitled main_last_first.py where last is your last/family name and first is your first name. Use lower case letters. Make sure to add the proper comment block at the top of the file. o Import the tasks file in order for the main() function in this file to be able to call functions in the tasks.py file that you have defined. ITP 115 2022-01-04 Page 8 of 21 o Import the interface file in order for the main() function in this file to be able to call functions in the interface.py file that you have defined. 7. Define and call the main() function in your main_last_first.py file. o Print the following message to the user: National Parks o Call the tasks.readParksFile() function to get the list of parks. If your CSV file is named “national_parks.csv”, then you do not need to have an argument. Let the function use the default value for the file name. The readParksFile() function has a return value, so make sure to use a variable to hold the list of parks that is returned. This list is a list of dictionary objects where each dictionary object holds the information for one national park. o Call the interface.getMenuDict() function to get the dictionary for the menu. o Use a loop to display the menu, get the user’s choice, and respond to the user’s choice while the user does not enter “Q” or “q”. o To display the menu use the interface.displayMenu() function. o To get input from the user, use the interface.getUserChoice() function. o Use branching to call the appropriate function in the interface file depending on the user’s input. 8. Be sure to comment your code. This means that there should be comments at the top of the files you created as well as throughout your code. Put a comment block at the top of each Python file. Put a comment block before each function stating the parameters, return values, and what that function does. Points will be deducted for not having comments. 9. Follow coding conventions. You should use lowerCamelCase or snake_case for variable names. You are welcome to create any variables that you need. 10. Test the program. Look at the Sample Output below. Assignments that do not run are subject to 20% penalty. For the search, your output may be different if you are only getting the description to the first comma. 11. Prepare your submission: o Find the project_last_first folder on your computer and compress it. This cannot be done within PyCharm. ITP 115 2022-01-04 Page 9 of 21 o On Windows, use File Explorer to select the folder. Right click and select the Send to -> Compressed (zipped) folder option. This will create a zip file. o On Mac OS, use Finder to select the folder. Right click and select the Compress “FolderName” option. This will create a zip file. 12. Upload the zip file to your Blackboard section: o On Blackboard, navigate to the Final Project item. o Click on the specific item for the Final Project. o Click on the Browse Local Files button and select the zip file. o Click the Submit button. ITP 115 2022-01-04 Page 10 of 21 Grading § This assignment is worth 100 points. § Make sure that you the program runs. Points will be taken off if the graders have to edit the source code to test your program. § Make sure to submit your assignment correctly as described above. Points will be taken off for improper submission. § You may NOT import and use the CSV modules or other modules to process the CSV file. Use the techniques from the course materials. Category Item Points project_last_first national_parks.csv in directory 2 tasks.py readParksFile() 12 convertDate() 6 getLargestPark() 8 interface.py getMenuDict() 5 displayMenu() 5 getUserChoice() 8 printAllParks() 10 getStateAbbr() 4 printParksInState() 6 printLargestPark() 2 printParksForSearch() 10 main_last_first.py import tasks & interface 2 main() 10 all files style & comments 10 Total 100 ITP 115 2022-01-04 Page 11 of 21 Sample Output National Parks A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park Q -> Quit Choice: e Choice: b Enter a state: aa There are no national parks in AA or it is not a valid state. A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park Q -> Quit Choice: B Enter a state: calif Need the t

💡 Buy the answer for only $12 Get it now →

wo letter abbreviation Enter a state: cal Need the two letter abbreviation Enter a state: ca Channel Islands National Park (CHIS) Location: CA Area: 249561 acres Date Established: March 05, 1980 Death Valley National Park (DEVA) Location: CA & NV Area: 4740912 acres Date Established: February 26, 1917 Joshua Tree National Park (JOTR) Location: CA Area: 789745 acres Date Established: October 31, 1994 Lassen Volcanic National Park (LAVO) Location: CA Area: 106372 acres Date Established: August 09, 1916 Pinnacles National Park (PINN) Location: CA Area: 26606 acres Date Established: January 10, 2013 ITP 115 2022-01-04 Page 12 of 21 Redwood National Park (REDW) Location: CA Area: 112512 acres Date Established: October 02, 1968 Sequoia and Kings Canyon National Parks (SEKI) Location: CA Area: 865952 acres Date Established: September 25, 1890 Yosemite National Park (YOSE) Location: CA Area: 761266 acres Date Established: October 01, 1890 A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park Q -> Quit Choice: c Wrangell – St Elias National Park and Preserve (WRST) Location: AK Area: 8323148 acres Date Established: December 02, 1980 Description: The largest national park in the system protects the convergence of the Alaska, Chugach, Wrangell, and Saint Elias Ranges, which include many of the continent’s tallest mountains and volcanoes, including the 18,008-foot Mount Saint Elias. More than a quarter of the park is covered with glaciers, including the tidewater Hubbard Glacier, piedmont Malaspina Glacier, and valley Nabesna Glacier. A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park Q -> Quit Choice: d Enter text for searching: cave Carlsbad Caverns National Park (CAVE) Location: NM Area: 46766 acres Date Established: May 14, 1930 Description: Carlsbad Caverns has 117 caves, the longest of which is over 120 miles (190 km) long. The Big Room is almost 4,000 feet (1,200 m) long, and the caves are home to over 400,000 Mexican free-tailed ITP 115 2022-01-04 Page 13 of 21 bats and sixteen other species. Above ground are the Chihuahuan Desert and Rattlesnake Springs. Great Basin National Park (GRBA) Location: NV Area: 77180 acres Date Established: February 26, 1919 Description: Based around Nevada’s second tallest mountain, Wheeler Peak, Great Basin National Park contains 5,000-year-old bristlecone pines, a rock glacier, and the limestone Lehman Caves. Due to its remote location, the park has some of the country’s darkest night skies. Wildlife includes the Townsend’s big-eared bat, pronghorn, and Bonneville cutthroat trout. Mammoth Cave National Park (MACA) Location: KY Area: 52830 acres Date Established: July 01, 1941 Description: With more than 400 miles (640 km) of passageways explored, Mammoth Cave is the world’s longest known cave system. Subterranean wildlife includes eight bat species, Kentucky cave shrimp, Northern cavefish, and cave salamanders. Above ground, the park provides recreation on the Green River, 70 miles of hiking trails, and plenty of sinkholes and springs. Pinnacles National Park (PINN) Location: CA Area: 26606 acres Date Established: January 10, 2013 Description: Named for the eroded leftovers of a portion of an extinct volcano, the park’s massive black and gold monoliths of andesite and rhyolite are a popular destination for rock climbers. Hikers have access to trails crossing the Coast Range wilderness. The park is one of the few locations the endangered California condor can be seen in the wild. Pinnacles also supports a dense population of prairie falcons and more than 13 species of bat that populate its talus caves. Sequoia and Kings Canyon National Parks (SEKI) Location: CA Area: 865952 acres Date Established: September 25, 1890 Description: This park protects the Giant Forest, which boasts some of the world’s largest trees, the General Sherman being the largest measured tree in the park. Other features include over 240 caves, a ITP 115 2022-01-04 Page 14 of 21 long segment of the Sierra Nevada including the tallest mountain in the contiguous United States, and Moro Rock, a large granite dome. Wind Cave National Park (WICA) Location: SD Area: 28295 acres Date Established: January 09, 1903 Description: Wind Cave is distinctive for its calcite fin formations called boxwork, a unique formation rarely found elsewhere, and needle- like growths called frostwork. It is one of the longest caves in the world and creates a wind as air pressure changes. Above ground is a mixed-grass prairie with animals such as bison, black-footed ferrets, and prairie dogs and ponderosa pine forests home to cougars and elk. The cave is culturally significant to the Lakota people as a creation site. A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park Q -> Quit Choice: d Enter text for searching: koala There are no national parks for the search term of ‘koala’. A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park Q -> Quit Choice: a Acadia National Park (ACAD) Location: ME Area: 47390 acres Date Established: February 26, 1919 Arches National Park (ARCH) Location: UT Area: 76519 acres Date Established: November 12, 1971 Badlands National Park (BADL) Location: SD Area: 242756 acres Date Established: November 10, 1978 Big Bend National Park (BIBE) Location: TX ITP 115 2022-01-04 Page 15 of 21 Area: 801163 acres Date Established: June 12, 1944 Biscayne National Park (BISC) Location: FL Area: 172924 acres Date Established: June 28, 1980 Black Canyon of the Gunnison National Park (BLCA) Location: CO Area: 32950 acres Date Established: October 21, 1999 Bryce Canyon National Park (BRCA) Location: UT Area: 35835 acres Date Established: February 25, 1928 Canyonlands National Park (CANY) Location: UT Area: 337598 acres Date Established: September 12, 1964 Capitol Reef National Park (CARE) Location: UT Area: 241904 acres Date Established: December 18, 1971 Carlsbad Caverns National Park (CAVE) Location: NM Area: 46766 acres Date Established: May 14, 1930 Channel Islands National Park (CHIS) Location: CA Area: 249561 acres Date Established: March 05, 1980 Congaree National Park (CONG) Location: SC Area: 26546 acres Date Established: November 10, 2003 Crater Lake National Park (CRLA) Location: OR Area: 183224 acres Date Established: May 22, 1902 Cuyahoga Valley National Park (CUVA) Location: OH Area: 32950 acres Date Established: October 11, 2000 Denali National Park and Preserve (DENA) Location: AK Area: 3372402 acres Date Established: October 31, 1994 ITP 115 2022-01-04 Page 16 of 21 Death Valley National Park (DEVA) Location: CA & NV Area: 4740912 acres Date Established: February 26, 1917 Dry Tortugas National Park (DRTO) Location: FL Area: 64701 acres Date Established: October 26, 1992 Everglades National Park (EVER) Location: FL Area: 1508538 acres Date Established: May 30, 1934 Gates Of The Arctic National Park and Preserve (GAAR) Location: AK Area: 7523898 acres Date Established: December 02, 1980 Glacier National Park (GLAC) Location: MT Area: 1013572 acres Date Established: May 11, 1910 Glacier Bay National Park and Preserve (GLBA) Location: AK Area: 3224840 acres Date Established: December 02, 1980 Great Basin National Park (GRBA) Location: NV Area: 77180 acres Date Established: February 26, 1919 Grand Canyon National Park (GRCA) Location: AZ Area: 1217403 acres Date Established: February 26, 1929 Great Sand Dunes National Park and Preserve (GRSA) Location: CO Area: 42984 acres Date Established: October 27, 1986 Great Smoky Mountains National Park (GRSM) Location: TN & NC Area: 521490 acres Date Established: September 24, 2004 Grand Teton National Park (GRTE) Location: WY Area: 309995 acres Date Established: June 15, 1934 Guadalupe Mountains National Park (GUMO) Location: TX ITP 115 2022-01-04 Page 17 of 21 Area: 86416 acres Date Established: October 15, 1966 Haleakala National Park (HALE) Location: HI Area: 29094 acres Date Established: July 01, 1961 Hawaii Volcanoes National Park (HAVO) Location: HI Area: 323431 acres Date Established: August 01, 1916 Hot Springs National Park (HOSP) Location: AR Area: 5550 acres Date Established: March 04, 1921 Isle Royale National Park (ISRO) Location: MI Area: 571790 acres Date Established: April 03, 1940 Joshua Tree National Park (JOTR) Location: CA Area: 789745 acres Date Established: October 31, 1994 Katmai National Park and Preserve (KATM) Location: AK Area: 3674530 acres Date Established: December 02, 1980 Kenai Fjords National Park (KEFJ) Location: AK Area: 669983 acres Date Established: December 02, 1980 Kobuk Valley National Park (KOVA) Location: AK Area: 1750717 acres Date Established: December 02, 1980 Lake Clark National Park and Preserve (LACL) Location: AK Area: 2619733 acres Date Established: December 02, 1980 Lassen Volcanic National Park (LAVO) Location: CA Area: 106372 acres Date Established: August 09, 1916 Mammoth Cave National Park (MACA) Location: KY Area: 52830 acres Date Established: July 01, 1941 ITP 115 2022-01-04 Page 18 of 21 Mesa Verde National Park (MEVE) Location: CO Area: 52122 acres Date Established: June 29, 1906 Mount Rainier National Park (MORA) Location: WA Area: 235625 acres Date Established: March 02, 1899 North Cascades National Park (NOCA) Location: WA Area: 504781 acres Date Established: October 02, 1968 Olympic National Park (OLYM) Location: WA Area: 922651 acres Date Established: June 29, 1938 Petrified Forest National Park (PEFO) Location: AZ Area: 93533 acres Date Established: December 09, 1962 Pinnacles National Park (PINN) Location: CA Area: 26606 acres Date Established: January 10, 2013 Redwood National Park (REDW) Location: CA Area: 112512 acres Date Established: October 02, 1968 Rocky Mountain National Park (ROMO) Location: CO Area: 265828 acres Date Established: January 26, 1915 Saguaro National Park (SAGU) Location: AZ Area: 91440 acres Date Established: October 14, 1994 Sequoia and Kings Canyon National Parks (SEKI) Location: CA Area: 865952 acres Date Established: September 25, 1890 Shenandoah National Park (SHEN) Location: VA Area: 199045 acres Date Established: December 26, 1935 Theodore Roosevelt National Park (THRO) Location: ND ITP 115 2022-01-04 Page 19 of 21 Area: 70447 acres Date Established: November 10, 1978 Voyageurs National Park (VOYA) Location: MN Area: 218200 acres Date Established: April 08, 1975 Wind Cave National Park (WICA) Location: SD Area: 28295 acres Date Established: January 09, 1903 Wrangell – St Elias National Park and Preserve (WRST) Location: AK Area: 8323148 acres Date Established: December 02, 1980 Yellowstone National Park (YELL) Location: WY & MT & ID Area: 2219791 acres Date Established: March 01, 1872 Yosemite National Park (YOSE) Location: CA Area: 761266 acres Date Established: October 01, 1890 Zion National Park (ZION) Location: UT Area: 146598 acres Date Established: November 19, 1919 A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park Q -> Quit Choice: 1 Choice: x Choice: q ITP 115 2022-01-04 Page 20 of 21 Extra Credit Add additional features to your menu. Define and call functions to implement the features. For each option, you will need to update the getMenuDict() function in the interface.py file and the main() function in the main_last_first.py file. You can implement one of the options or both of them. Print oldest park – 5 points Determine the oldest national park by using the oldest established year. The year is in the value of the “Date” key in the dictionary for each park. Print the park including the description. Print state with most parks – 5 points Determine the state with the most parks. (There are two solutions. You only have to print one state and its parks.) Print the state and its parks. Look at the sample output below. Sample Output for Extra Credit National Parks A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park E -> The oldest park F -> State with most parks Q -> Quit Choice: e Yellowstone National Park (YELL) Location: WY & MT & ID Area: 2219791 acres Date Established: March 01, 1872 Description: Situated on the Yellowstone Caldera, the park has an expansive network of geothermal areas including boiling mud pots, vividly colored hot springs such as Grand Prismatic Spring, and regularly erupting geysers, the best-known being Old Faithful. The yellow-hued Grand Canyon of the Yellowstone River contains several high waterfalls, and four mountain ranges traverse the park. More than 60 mammal species including timber wolves, grizzly bears, black bears, lynxes, bison, and elk make this park one of the best wildlife viewing spots in the country. ITP 115 2022-01-04 Page 21 of 21 A -> All national parks B -> Parks in a particular state C -> The largest park D -> Search for a park E -> The oldest park F -> State with most parks Q -> Quit Choice: f The state with the most parks is CA Channel Islands National Park (CHIS) Location: CA Area: 249561 acres Date Established: March 05, 1980 Death Valley National Park (DEVA) Location: CA & NV Area: 4740912 acres Date Established: February 26, 1917 Joshua Tree National Park (JOTR) Location: CA Area: 789745 acres Date Established: October 31, 1994 Lassen Volcanic National Park (LAVO) Location: CA Area: 106372 acres Date Established: August 09, 1916 Pinnacles National Park (PINN) Location: CA Area: 26606 acres Date Established: January 10, 2013 Redwood National Park (REDW) Location: CA Area: 112512 acres Date Established: October 02, 1968 Sequoia and Kings Canyon National Parks (SEKI) Location: CA Area: 865952 acres Date Established: September 25, 1890 Yosemite National Park (YOSE) Location: CA Area: 761266 acres Date Established: October 01, 1890

💡 Buy the answer for only $12 Get it now →