Goals
In this project, you will estimate the future populations of different countries based on their current populations and growth rates over a multi-year period. You will also prepare a summary report indicating average population, number of countries with very low/high growth rate and countries with the largest initial and final population.
You will be practicing the following concepts from prior labs:
for
-loops- conditionals
- math calculations
- accumulator pattern
- min/max calculations
- non-trivial
print
statements
Summary
In this project, you will write a program that prompts the user for number of countries, their initial population, growth rate and then computes the population for some number of future years. Your program will report summary statistics related to growth rate and estimated population of these countries. This program will be built in stages: Checkpoint A, Checkpoint B, and then Final Code. There is a demo associated with each intermediate stage.
Part of this project is an exercise in having control over functions and patterns to produce target outputs. It is not a creative exercise, but rather the opportunity for you to demonstrate precision, control and being detail-oriented. You are asked to demonstrate the requested behavior and output, matching the sample output exactly. In all samples below, user input is shown in italics and underlined.
Due Dates
- Checkpoint A: Due as a demo in any lab, drop-in tutoring or workshop before Friday, Sep. 14 at 5 PM.
- Checkpoint B: Due as a demo in any lab, drop-in tutoring or workshop before Sunday, Sep. 23 at 8 PM.
- Final Code: Due via Moodle on Thursday, Sep. 27 at 11:55 PM.
Checkpoint A
For Checkpoint A, you will need to demonstrate a program that does the following:
- Prints the header line
- Prompts the user for the number of countries. You can assume that the user always enters a positive integer.
- Prints a subheading for each country. For example:
- Prompts the user for each country's name, initial population (in millions) and annual population growth rate (as a percentage). You can assume that the initial population will be a valid positive number, and the growth rate will be a valid (possibly negative) number.
- Estimates and prints each country's population the following year (year 2) and rounds it off to 3 decimal places.
- Estimates and prints the average population of these countries in year 2 and rounds it off to 3 decimal places.
Matches the sample input/output below.
We will use additional sample inputs to test your demo and your final program, and so should you.
- Demo. Demo Checkpoint A.
=== POPULATION GROWTH ESTIMATOR ===
--- Country 1 ---
Sample Input/Output
- Sample 1
=== POPULATION GROWTH ESTIMATOR === This program estimates population growth of several countries Number of countries: 1 --- Country 1 --- Country name: USA Year 1 population (in millions): 313.9 Population growth rate (% per year): 0.9 Year 2 population (in millions): 316.725 Summary Report Average year 2 population of all countries: 316.725
In this sample, notice that the initial population and the growth rate come from the user, and the Year 2 population is computed by your program. In addition, the average population is same as year 2 population of USA because there is only 1 country.
- Sample 2
=== POPULATION GROWTH ESTIMATOR === This program estimates population growth of several countries Number of countries: 3 --- Country 1 --- Country name: Qatar Year 1 population (in millions): 2.051 Population growth rate (% per year): 4.93 Year 2 population (in millions): 2.152 --- Country 2 --- Country name: Latvia Year 1 population (in millions): 2.025 Population growth rate (% per year): -0.6 Year 2 population (in millions): 2.013 --- Country 3 --- Country name: USA Year 1 population (in millions): 313.9 Population growth rate (% per year): 0.9 Year 2 population (in millions): 316.725 Summary Report Average year 2 population of all countries: 106.963
Checkpoint B
For Checkpoint B, you will extend your code from Checkpoint A to do the following:
- Prompt the user for N, the number of years for which the population is to be estimated for each country. The initial population counts as the first year. You may assume that the user will enter a positive integer.
- Instead of just estimating the Year 2 population of each country, you will estimate the population for years 2 through N.
- Instead of computing the average of Year 2 population of all countries, you will compute and print the average of Year N population.
- When prompting for Year 1 population and printing out population of following years, indicate the name of country.
- Compute and print the number of countries whose growth rate is greater than 1.
- Compute and print the number of countries whose growth rate is smaller than or equal to 0.1.
- Compute and print the name of country with highest growth rate.
Match the sample input/output below exactly.
- Demo. Demo Checkpoint B.
Advice and Hints
Hint: float('inf')
is larger than every other float, and float('-inf')
is smaller than every other float. You may find these useful as variable initializers, when you are tracking minima and maxima.
Sample Input/Output
- Sample 3
=== POPULATION GROWTH ESTIMATOR === This program estimates population growth of several countries Number of countries: 3 Number of years: 3 --- Country 1 --- Country name: Qatar Year 1 population of Qatar (in millions): 2.051 Population growth rate (% per year): 4.93 Year 2 population of Qatar (in millions): 2.152 Year 3 population of Qatar (in millions): 2.258 --- Country 2 --- Country name: Latvia Year 1 population of Latvia (in millions): 2.025 Population growth rate (% per year): -0.6 Year 2 population of Latvia (in millions): 2.013 Year 3 population of Latvia (in millions): 2.001 --- Country 3 --- Country name: USA Year 1 population of USA (in millions): 313.9 Population growth rate (% per year): 0.9 Year 2 population of USA (in millions): 316.725 Year 3 population of USA (in millions): 319.576 Summary Report Average year 3 population of all countries: 107.945 Number of countries with high growth rate: 1 Number of countries with low growth rate: 1 Country with highest growth rate: Qatar
- Sample 4
=== POPULATION GROWTH ESTIMATOR === This program estimates population growth of several countries Number of countries: 4 Number of years: 5 --- Country 1 --- Country name: Malaysia Year 1 population of Malaysia (in millions): 29.18 Population growth rate (% per year): 1.54 Year 2 population of Malaysia (in millions): 29.629 Year 3 population of Malaysia (in millions): 30.086 Year 4 population of Malaysia (in millions): 30.549 Year 5 population of Malaysia (in millions): 31.019 --- Country 2 --- Country name: Peru Year 1 population of Peru (in millions): 29.55 Population growth rate (% per year): 1.02 Year 2 population of Peru (in millions): 29.851 Year 3 population of Peru (in millions): 30.156 Year 4 population of Peru (in millions): 30.463 Year 5 population of Peru (in millions): 30.774 --- Country 3 --- Country name: Morocco Year 1 population of Morocco (in millions): 32.309 Population growth rate (% per year): 1.05 Year 2 population of Morocco (in millions): 32.648 Year 3 population of Morocco (in millions): 32.991 Year 4 population of Morocco (in millions): 33.337 Year 5 population of Morocco (in millions): 33.688 --- Country 4 --- Country name: Afghanistan Year 1 population of Afghanistan (in millions): 30.42 Population growth rate (% per year): 2.22 Year 2 population of Afghanistan (in millions): 31.095 Year 3 population of Afghanistan (in millions): 31.786 Year 4 population of Afghanistan (in millions): 32.491 Year 5 population of Afghanistan (in millions): 33.213 Summary Report Average year 5 population of all countries: 32.173 Number of countries with high growth rate: 4 Number of countries with low growth rate: 0 Country with highest growth rate: Afghanistan
- Sample 5
=== POPULATION GROWTH ESTIMATOR === This program estimates population growth of several countries Number of countries: 2 Number of years: 4 --- Country 1 --- Country name: Latvia Year 1 population of Latvia (in millions): 2.025 Population growth rate (% per year): -0.6 Year 2 population of Latvia (in millions): 2.013 Year 3 population of Latvia (in millions): 2.001 Year 4 population of Latvia (in millions): 1.989 --- Country 2 --- Country name: Bulgaria Year 1 population of Bulgaria (in millions): 3.22 Population growth rate (% per year): -0.22 Year 2 population of Bulgaria (in millions): 3.213 Year 3 population of Bulgaria (in millions): 3.206 Year 4 population of Bulgaria (in millions): 3.199 Summary Report Average year 4 population of all countries: 2.594 Number of countries with high growth rate: 0 Number of countries with low growth rate: 2 Country with highest growth rate: Bulgaria
- If the user inputs a non-positive number for number of countries or number of years, then print an error message and exit (see sample 6 below).
- Print out the names and populations of the countries with the largest initial (Year 1) and final (Year N) populations.
Match the sample input/output below exactly.
- Sample 6
=== POPULATION GROWTH ESTIMATOR === This program estimates population growth of several countries Number of countries: 0 Error: 0 is not a valid input
- Sample 7
=== POPULATION GROWTH ESTIMATOR === This program estimates population growth of several countries Number of countries: 2 Number of years: 10 --- Country 1 --- Country name: India Year 1 population of India (in millions): 1354.051 Population growth rate (% per year): 1.11 Year 2 population of India (in millions): 1369.081 Year 3 population of India (in millions): 1384.278 Year 4 population of India (in millions): 1399.643 Year 5 population of India (in millions): 1415.179 Year 6 population of India (in millions): 1430.888 Year 7 population of India (in millions): 1446.771 Year 8 population of India (in millions): 1462.83 Year 9 population of India (in millions): 1479.067 Year 10 population of India (in millions): 1495.485 --- Country 2 --- Country name: China Year 1 population of China (in millions): 1415.046 Population growth rate (% per year): 0.39 Year 2 population of China (in millions): 1420.565 Year 3 population of China (in millions): 1426.105 Year 4 population of China (in millions): 1431.667 Year 5 population of China (in millions): 1437.25 Year 6 population of China (in millions): 1442.855 Year 7 population of China (in millions): 1448.483 Year 8 population of China (in millions): 1454.132 Year 9 population of China (in millions): 1459.803 Year 10 population of China (in millions): 1465.496 Summary Report Average year 10 population of all countries: 1480.49 Number of countries with high growth rate: 1 Number of countries with low growth rate: 0 Country with highest growth rate: India Country with maximum Year 1 population (1415.046 million): China Country with maximum Year 10 population (1495.485 million): India
- Sample 8
=== POPULATION GROWTH ESTIMATOR === This program estimates population growth of several countries Number of countries: 3 Number of years: 5 --- Country 1 --- Country name: Colombia Year 1 population of Colombia (in millions): 49.46 Population growth rate (% per year): 1.0 Year 2 population of Colombia (in millions): 49.955 Year 3 population of Colombia (in millions): 50.454 Year 4 population of Colombia (in millions): 50.959 Year 5 population of Colombia (in millions): 51.468 --- Country 2 --- Country name: Italy Year 1 population of Italy (in millions): 60.6 Population growth rate (% per year): 0.1 Year 2 population of Italy (in millions): 60.661 Year 3 population of Italy (in millions): 60.721 Year 4 population of Italy (in millions): 60.782 Year 5 population of Italy (in millions): 60.843 --- Country 3 --- Country name: Hungary Year 1 population of Hungary (in millions): 9.818 Population growth rate (% per year): -0.25 Year 2 population of Hungary (in millions): 9.793 Year 3 population of Hungary (in millions): 9.769 Year 4 population of Hungary (in millions): 9.745 Year 5 population of Hungary (in millions): 9.72 Summary Report Average year 5 population of all countries: 40.677 Number of countries with high growth rate: 0 Number of countries with low growth rate: 2 Country with highest growth rate: Colombia Country with maximum Year 1 population (60.6 million): Italy Country with maximum Year 5 population (60.843 million): Italy
- Checkpoints [20%]
-
Checkpoint demos are each worth 10 points; each is all or nothing.
- Programming Design and Style [25%]
-
In addition to being correct, your program should be easy to understand and well documented. For details, see the rubric below.
- Correctness [55%]
-
The most important part of your grade is the correctness of your final program. Your program will be tested numerous times, using different inputs, to be sure that it meets the specification. You will not get full credit for this unless your output matches the sample output exactly for every case, including capitalization and spacing. Attention to detail will pay off on this assignment. For details, see the rubric below.
- Docstring (5 points)
- There should be a docstring at the top of your submitted file with the following information:
1 pt. Your name (first and last) 1 pt. The course (CS 115) 1 pt. The assignment (e.g., Project 1) 2 pts. A brief description of what the program does - Documentation (6 points)
- Not counting the docstring, your program should contain at least three comments explaining aspects of your code that are potentially tricky for a person reading it to understand. You should assume that the person understands what Python syntax means but may not understand why you are doing what you are doing.
6 pts. You have at least 3 useful comments (2 points each) - Variables (5 points)
-
5 pts. Variables have helpful names that indicate what kind of information they contain. - Algorithm (4 points)
-
2 pts. Your algorithm is straightforward and easy to follow. 2 pts. Your algorithm is reasonably efficient, with no wasted computation or unused variables. - Program structure (5 points)
- All or nothing: your code should define a main function and then call that function, just like our programs do in the lab. Other than library imports, the docstring, and the final call to
main()
, you should not have any stray code outside a function definition. - Catchall
- For students using language features that were not covered in class, up to 5 points may be taken off if the principles of programming style are not adhered to when using these features. If you have any questions about what this means, then ask.
- Copying part or all of another student's assignment
- Copying old or published solutions
- Looking at another student's code or discussing it in great detail. You will be penalized if your program matches another student's program too closely.
- Showing your code or describing your code in great detail to anyone other than the course staff or tutor.
Final Code
In your final code, you will extend the above code to do the following:
There is no demo for your final code.
Extra Credit
You can get extra credit by computing minimum year 1 and year N population in the summary report (+2.5).
You can get extra credit by computing average mid-year population in the summary report when the number of years are odd. For example, if number of years are 17, then average population for year 8 should be reported (in addition to average population for year 17). But if the number of years are 18, then only the average population for year 18 should be reported (+7.5).
If you have other ideas/suggestions for extra-credit, feel free to run it by the instructor before implementing it.
You will get no more than 10 points total for extra credit. Be sure you describe any extra-credit work in your docstring, explaining the judgements you made and you must include references justifying these judgements. If you do not describe your extra credit work, it will get ignored.
Grading Rubric
Detailed Rubric
Correctness: functional features (50 points -- 5 points each)
Feature 1: | Includes the name of country when prompting for year 1 population or displaying years 2 - N population (Ex: Samples 3 - 8). |
Feature 2: | Estimates the population for years 2 - N correctly and to 3 decimal places (Ex: Samples 3 - 8). |
Feature 3: | Computes the average year N population corectly (Ex: Samples 1 - 8). |
Feature 4: | Computes correctly the number of countries with high/low growth rate (Ex: Samples 3 - 8). |
Feature 5: | Computes correctly the number of countries with high/low growth rate when all countries have negative growth rate (Ex: Sample 5). |
Feature 6: | Computes correctly the country with highest growth rate (Ex: Samples 3 - 8). |
Feature 7: | When the user inputs an invalid number for the number of countries and number of years, the program produces an appropriate error message and exit code (Ex: Sample 6). |
Feature 8: | Computes correctly the country with maximum year 1 population (Ex: Samples 7 - 8). |
Feature 9: | Computes correctly the country with maximum year N population (Ex: Samples 7 - 8). |
Feature 10: | Code should produce correct output when either or both of number of countries and number of years is 1. |
Correctness: spacing, spelling, grammar, punctuation (5 points)
Your spelling, punctuation, etc. get a separate score: each minor error in spacing, punctuation, or spelling gets a score of 2.5, and each major error gets a score of 5. Here is how the score translates to points on the assignment:
[5] | Score = 0 |
-1 | 0 < Score <= 2.5 |
-2 | 2.5 < Score <= 5 |
-3 | 5 < Score <= 7.5 |
-4 | 7.5 < Score <= 10 |
-5 | Score > 10 |
Programming Design and Style (25 points)
Submission
You should submit your final code on Moodle by the deadline. I strongly encourage you to take precautions to make and manage backups while you work on your project, in case something goes wrong either while working or with your submission to Moodle.
Name the file you submit to Moodle yourlastnameP1.py
, substituting your actual last name (in lowercase) for yourlastname.
Late Policies
Project late policies are outlined in the course policies page.
Collaboration Policy
Programming projects must be your own work, and academic misconduct is taken very seriously. You may discuss ideas and approaches with other students and the course staff, but you should work out all details and write up all solutions on your own. The following actions will be penalized as academic dishonesty: