CECS 100
LAB ASSIGNMENT 10
Assigned date: 11/4
Due date: Monday 11/13
30 points
Do problem 9 (Population Data) in chapter 7 on page 404. Data file
Please submit the lab assignment to Beachboard by Friday, November 8.
Since we do not meet this week, I provide some guidelines on how to do the problem 1.
# The program assumes that all population changes are positive.
# That is, that each year the population was larger than the
# previous year.
def main():
# Setup variables
yearly_change = []
change = 0.0
total_change = 0.0
average_change = 0.0
greatest_increase = 0.0
smallest_increase = 0.0
greatest_year = 0
smallest_year = 0
# Constant for the base year
BASE_YEAR = 1950
try:
# Open the file for reading.
________________________________________________
# Read all the lines in the file into a list.
____________________________________
# Turn all read strings into numbers. Use a for in loop
______________________
yearly_population[i] = ________________________ # use float operator to convert string into numbers
# Calculate the change in population size for each two years.
for i in range(1, len(yearly_population)):
change = yearly_population[i] -___________________
yearly_change.append(change)
# If this is the first year, set trackers to its value.
if i==1:
greatest_increase = change
smallest_increase = _____________
greatest_year = 1
smallest_year = ___________
# This is not the first change in population size.
# Update trackers if relevant.
else:
if change > greatest_increase:
greatest_increase = _________
greatest_year = i
elif _____________________
_____________________
_____________________
total_change = _________________________ # use sum function and float
average_change = ________________________________
print('The average annual change in population ' \
'during the time period is', format(______________________)) # format to 2 decimal places
print('The year with the greatest increase in population was', \
_______________________)
print('The year with the smallest increase in population was', \
__________________________)
except IOError:
print('The file could not be found.')
except IndexError:
print('There was an indexing error.')
except:
print('An error occurred.')
# Call the main function.
main()
Grading
Criteria | Approx. % of Grade | Excellent (100%) | Adequate (80%) | Poor (60%) | Not Met (0%) |
---|---|---|---|---|---|
Program Specification /Correctioness | 50%(10 points) | No errors, program always works correctly and meets the specification(s). | Minor details of the program specification are violated, program functions incorrectly for some inputs. | Significant details of the specification are violated, program often exhibits incorrect behavior. | Program only functions correctly in very limited cases or not at all. |
Readability | 20% (4 points) | No errors, code is clean, understandable, and well-organized. | Minor issues with consistent indentation, use of whitespace, variable naming, or general organization. | At least one major issue with indentation, whitespace, variable names, or organization. | Major problems with at three or four of the readability subcategories. |
Documentation | 10% (2 points) | No errors, code is well-commented. | One or two places that could benefit from comments are missing them or the code is overly commented. | File header missing, complicated lines or sections of code uncommented or lacking meaningful comments. | No file header or comments present. |
Code Efficiency | 15% (3 points) | No errors, code uses the best approach in every case. | No errors, code uses the working approach in every case. | Code uses poorly-chosen approaches in at least one place. | Many things in the code could have been accomplished in an easier, faster, or otherwise better fashion. |
Assignment Specifications | 5% (1 point) | No errors | N/A | Minor details of the assignment specification are violated, such as files named incorrectly or extra instructions slightly misunderstood. | Significant details of the specification are violated, such as extra instructions ignored or entirely misunderstood. |