[Tutor] Program help
alexkleider
alexkleider at protonmail.com
Fri Oct 23 14:25:52 EDT 2020
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, October 22, 2020 3:16 PM, nathan tech <nathan-tech at hotmail.com> wrote:
> 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
The for loop didn't seem quite right to me since data appears to be a list.
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> d = ['1', '3', '4']
>>> for x in range(d):
... data[x] = int(d[x])
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'list' object cannot be interpreted as an integer
>>>
... or am I missing something?
More information about the Tutor
mailing list