[Tutor] Program help

Alan Gauld alan.gauld at yahoo.co.uk
Thu Oct 22 18:47:14 EDT 2020


On 22/10/2020 18:02, Garrett Phelps wrote:
> Perhaps someone can help me write this code:

We are happy to help but won't do it for you...
So you need to show us your code and ask specific questions.
If you get errors include the *full* error message not a summary.

> The USPopulation.txt file contains the midyear population of United States,
> in thousands, during the years 1950 through 1990. The first line in the
> file contains the population for 1950, the second line contains the
> population for 1951, and so forth. Create an application that reads the
> file's contents into a list. The application should do the following:
> 
>    - (15 points) Read the file into an list of integers (multiply by 1000)

Have you done this bit?

>    - Iterate through the array and display:
>       - (10 points) Year
>       - Population

This should be straightforward, have you got it working?

>       - (10 points) Change from previous year (subtract current year minus
>       previous year)

This is a bit harder but uses a similar approach to a recent thread
about removing duplicates from a list, take a look in the archives.

>       - (10 points) Percent change in population over last year (change in
>       population divided by previous year population)

If you got the last bit this is easy.

>    - When complete, display the following based on the changes in
>    population (not changes in percent):
>       - (10 points) Average Population Change
>       - (10 points) Minimum Population Change and Year
>       - (10 points) Maximum Population Change and Year

This is slightly more tricky, you need to keep some running values
But if you did that then its not too hard.

Now, how far have you got? Which bits are sticking?
Show us your code.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list