[Tutor] Program help
nathan tech
nathan-tech at hotmail.com
Thu Oct 22 18:16:56 EDT 2020
Hi Garrett
This reads rather like a homework assignment! :)
Here are some tips that I hope may help:
think through what you need to do:
1. Load the data.
2. Do something with the data.
3. Display the data in some way.
the first bit is quite easy:
f=open("population.txt","r")
data=f.read()
f.close()
data=data.split("\n")
Convert it to numbers:
for x in range(data):
data[x]=int(data[x])
The rest is just some fancy footwork with a for loop like the one above
and some organisation into variables depending on what you want to do
with it.
Hope this helps!
Nathan
On 22/10/2020 18:02, Garrett Phelps wrote:
> Perhaps someone can help me write this code:
>
> 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)
> - Iterate through the array and display:
> - (10 points) Year
> - Population
> - (10 points) Change from previous year (subtract current year minus
> previous year)
> - (10 points) Percent change in population over last year (change in
> population divided by previous year population)
> - 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
>
> Best Regards,
> Garrett Phelps
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&data=04%7C01%7C%7C4ebacf3dddaf46f45fa708d876d0fbf3%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637389987231288846%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=AnQRyun6MqNQhcGAAMK%2BnLUPHn4fjgrEMrziPdYZdPU%3D&reserved=0
More information about the Tutor
mailing list