Question: Exercise 2: Student's Choice (solve either Exercise 2A or 2B) Exercise 2A Create a Python program that reads the data stored in the provided rainfall.txt,


Exercise 2: Student's Choice (solve either Exercise 2A or 2B) Exercise 2A Create a Python program that reads the data stored in the provided rainfall.txt, where cach line in the text file contains the name of a city, followed by whitespace, followed by the city's annual rainfall (in mm). Process this data so that it is grouped by annual rainfall into the following categories: (50-60 mm). (60-70 mm). [70-80 mm). [80-90 mm). [96-100 mm), and then sorted from lowest to highest rainfall within each category. Write this processed data to a new file called rainfallfmt.txt, so that under each category the city name is centered in a field that is 25 characters wide and is in all uppercase letters. The city name should be followed by its rainfall right-aligned in a field that is 5 characters wide with 1 digit to the right of the decimal point. Exercise 2A: Sample Output (50-60 mm) (60-70 mm) AKRON 65.6 ALTON 69.7 [70-80 mm) ALGONA 78.0 [B0-90 mm) BRITT 80.1 CARROLL 84.7 ANKENY 84.8 Exercise 2B: Create a Python program that reads the data stored in the provided earthquake.txt, where each line in the text file contains an carthquake magnitude, the date of the earthquake, the time, latitude, longitude, depth, and region, all separated by whitespace. Use the data to create lists of earthquake magnitudes and their dates, one for each region. Write these lists in any order) to a new file called earthquakefmt.txt, formatted to match the sample output below. Exercise 2B Sample Output: ALASKA, 2006/10/19, 2.81, 12006/10/16, 2.6), [2006/10/18, 2.7). [2006/10/18, 2.71. [2006/10/16, 2.81) (HAMAIT. (2006/10/19, 2.51. 2006/10/20.3.111 (PANAMA, 2006/10/18, 5.011 (MISSOURI, (2006/10/18, 3.411 INDONESIA, (2006/10/20, 4.911 VANUATU, 2006/10/18, 6.211 INEXICO, 2006/10/20.2.8). (2006/10/18, 3.311 Done earthquake 2 2.8 2006/10/19 02:02:10 62.391 - 149.751 15.0 CENTRAL ALASKA 2.5 2006/10/19 00:31:15 20.119 -156.213 1.5 MAUI REGION, HAWAII 5.0 2006/10/18 21:15:51 4.823 - 82.592 37.3 SOUTH OF PANAMA 2.6 2006/10/18 21:12:25 59.934 -147.904 30.0 GULF OF ALASKA 3.4 2006/10/18 20:59:21 36.540 -89.640 7.7 SOUTHEASTERN MISSOURI 2.7 2006/10/18 20:11:22 61.023 -151.418 60.0 SOUTHERN ALASKA 3.1 2006/10/20 16:40:15 20.282 -156.611 4.7 MAUI REGION, HAWAII 2.7 2006/10/18 14:12:19 59.808 -152.538 50.0 SOUTHERN ALASKA 2.8 2006/10/18 14:02:12 60.686-151.871 90.0 KENAI PENINSULA, ALASKA 4.9 2006/10/20 12:10:01 1.758 127.488 127.0 HALMAHERA, INDONESIA 6.2 2006/10/18 10:45:36 -15.081 167.243 138.5 VANUATU 2.8 2006/10/20 10:45:17 32.162 -115.895 6.3 BAJA CALIFORNIA, MEXICO 3.3 2006/10/18 10:08:45 32.165 - 115.891 7.3 BAJA CALIFORNIA, MEXICO Done rainfall Akron 65.5574 Albia 95.631 Algona 77.9526 Allison 85.4456 Alton 69.6722 AmesW 86.5378 AmesSE 86.233 Anamosa 89.7382 Ankeny 84.7852 Atlantic 88.3158 Audubon 84.8614 Beaconsfield 89.5858 Bedford 92.329 BellePlaine 90.9574 Bellevue 87.249 Blockton 92.1512 Bloomfield 96.5708 Boone 92.202 Brighton 85.3186 Britt 80.1116 Buckeye 85.4964 BurlingtonKBUR 96.3676 Burlington 93.8276 Carroll 84.6582 Cascade 85.0392
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
