[Solved] Computer Project #05

30 $

File Name: Computer_Project_#05.zip
File Size: 188.4 KB

SKU: [Solved] Computer Project #05 Category: Tag:

Or Upload Your Assignment Here:


Assignment OverviewThis assignment focuses on the implementation of Python programs to read files and process data byusing lists and functions.

Assignment DeliverableThe deliverable for this assignment is the following file: proj05.py – the source code for your Python programBe sure to use the specified file name and to submit it for grading via the handin system before the project deadline.

Assignment BackgroundU.S. Geological Survey (USGS) provides scientific information to understand Earth, manage resources and minimize loss from natural disasters. You can download interesting data from the website https://www.usgs.gov/We have downloaded the flow rate data for the Red Cedar River in East Lansing starting from 1932 . Your task is to design and implement a Python program that draws two plots from the data (and displays a table of data for each plot).Here is the first line of the file. The numbers that we are interested are the last three numbers which are year, month and flow rate in cubic feet per second (CFS). Notice that the year and month are ints and the flow rate is float:USGS 04112500 00060 70495 1932 1 215.5

Assignment Specifications1. The program must provide following functions to extract some statistics.a) open_file()prompts the user to enter a file name. The program will try to open the data file. Appropriate error message should be shown if the data file cannot be opened. This function will loop until it receives proper input and successfully opens the file. It returns a file pointer.b) read_file()calls the open_file() function and uses the returned file pointer to read the data file. This function returns a list of your choosing containing data you need for other parts of this project.c) draw_plot( x, y, plt_title, x_label, y_label) provided by us takes two equal-length lists of numbers and plots them. You need to pass the label strings and plot title to the function. Include the range of years in the title (Hint: use string concatenation and check sample output).d) annual_average(L) takes a list as an argument and returns a list of tuples in the form (year, average_flow).e) month_average(L,M) takes a list L and month M as arguments and returns a list of tuples in the form (year, month_flow). (Note: this originally left out the month M parameter—if you figured out how to solve the problem using the previous specification, you will get full credit.)f) You may use extra functions, if you wish.2. The program should read the file only once.3. The program should plot the average flow for each year. That is, find the average flow for each year and then generate a plot with years on the x-axis and average flow for that year on the y-axis. Then generate a table that has the year and average flow on each line. Put a title on the table and label each column.4. Next, the program should prompt the user for a number in the range 1-12 and should plot the flow rates for only that month. For example if user enters 1, the program should extract the flow rate of Jan 1932, Jan 1933, … , Jan 2015 and plot them. (Note: do not loop and ask for more.)5. The program should re-prompt the user if an invalid input (either wrong type or wrong value), was entered for the month. If something other than an integer is input, your error message should include the phrase “not an integer.” If an integer is input but it is not in the proper range, your error message should include the phrase “integer out of range.” Note: use exceptions.6. The month name should be displayed in the title of the second plot instead of the month number. Forexample, in the sample below you see “May” in the title. (Hint: use the month number as an index intoa list of strings.) As with the previous plot, display a table of values that you plotted.Assignment Notes1. Items 1-9 of the Coding Standard will be enforced for this project.2. Note that data are separated using spaces. You can use the list method .split() to split the line into alist of data.3. It is much easier to convert the input data to int and float when the program reads the file and createsthe list.4. To create a list L of data begin with an empty list (e.g. L = [] before the loop begins) and withinthe loop append to the list one item at a time, e.g. L.append(item). The data item you appendmay be a collection such as a tuple or another list.Suggested Procedure• Solve the problem using pencil and paper first. You cannot write a program until you havefigured out how to solve the problem. This first step may be done collaboratively with anotherstudent. However, once the discussion turns to Python specifics and the subsequent writing ofPython statements, you must work on your own.• Construct the program one function at a time—testing before moving on.• Use the handin system to turn in the first version of your solution.Cycle through the steps to incrementally develop your program:o Edit your program to add new capabilities.o Run the program and fix any errors.o Use the handin system to submit the current version of your solution.• Be sure to log out when you leave the room, if you’re working in a public lab.Sample Outputrunfile(‘/Users/enbody/Documents/cse231/FS16/Projects/Project05/proj05.py’,wdir=’/Users/enbody/Documents/cse231/FS16/Projects/Project05′)Input a file name: BadFileNameError: Input a file name: RedCedarRiver.txtAnnual Average FlowYear Flow1932 192.101933 185.741934 72.881935 132.311936 103.251937 204.471938 194.361939 123.071940 144.651941 127.251942 211.361943 319.971944 159.201945 206.771946 150.001947 350.341948 315.481949 210.721950 369.481951 275.351952 252.571953 135.011954 221.321955 156.291956 267.831957 216.151958 105.791959 287.531960 234.021961 118.081962 141.411963 92.311964 46.621965 164.561966 152.281967 210.721968 282.761969 244.501970 185.691971 176.131972 225.501973 319.701974 329.131975 350.861976 272.381977 123.581978 137.611979 152.611980 206.371981 250.231982 236.561983 238.591984 164.651985 337.971986 299.211987 142.121988 195.681989 229.191990 292.001991 223.881992 340.071993 380.491994 376.621995 221.571996 191.861997 243.131998 269.271999 145.652000 164.972001 315.152002 182.422003 127.922004 234.912005 208.332006 278.902007 256.092008 356.992009 373.352010 187.872011 331.622012 162.272013 238.762014 257.952015 186.90Enter a month (1-12): xxxxError. Not an integerEnter a month (1-12): 13Error. Integer out of range.Enter a month (1-12): -5Error. Integer out of range.Enter a month (1-12): 5Average Flow for MayYear Flow1932 362.401933 354.501934 65.401935 190.001936 103.601937 376.301938 214.601939 100.401940 94.501941 99.901942 99.301943 1008.001944 325.301945 772.401946 143.001947 619.501948 959.301949 150.201950 252.501951 307.901952 262.701953 253.701954 134.701955 94.601956 1310.001957 482.801958 78.301959 201.701960 293.001961 195.001962 164.501963 176.801964 121.601965 95.501966 284.401967 167.201968 211.401969 474.101970 261.201971 101.101972 234.101973 305.801974 507.101975 341.101976 401.701977 146.601978 206.301979 182.301980 246.201981 354.401982 143.601983 591.901984 306.201985 187.601986 186.501987 87.901988 131.201989 197.301990 348.401991 218.501992 249.801993 316.601994 296.001995 272.601996 403.401997 271.801998 436.801999 186.402000 354.902001 446.702002 329.502003 255.802004 692.802005 158.902006 481.402007 387.702008 141.302009 544.702010 485.002011 839.202012 273.102013 294.202014 576.702015 165.10Educational ResearchWhen you have completed the project insert the 5-line comment specified below.For each of the following statements, please respond with how much they apply to your experiencecompleting the programming project, on the following scale:1 = Strongly disagree / Not true of me at all234 = Neither agree nor disagree / Somewhat true of me567 = Strongly agree / Extremely true of me***Please note that your responses to these questions will not affect your project grade, so pleaseanswer as honestly as possible.***Q1: Upon completing the project, I felt proud/accomplishedQ2: While working on the project, I often felt frustrated/annoyedQ3: While working on the project, I felt inadequate/stupidQ4: Considering the difficulty of this course, the teacher, and my skills, I think I will do well inthis course.Please insert your answers into the bottom of your project program as a comment, formatted exactly asfollows (so we can write a program to extract them).# Questions# Q1: 5# Q2: 3# Q3: 4# Q4: 6

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Computer Project #05
30 $