Blue Week Special Offer | Brighten your week!

I am stuck! Please help

Screen Link:
My Code:

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

for app in apps_data[1]:
    price = float(app[4])
    if price == 0.0:
        app.append ('free')
        app.append ('non-free')

What I expected to happen:
I expected my code to run

What actually happened:

AttributeErrorTraceback (most recent call last)
<ipython-input-1-83f5f3348ffc> in <module>()
     13         app.append ('free')
     14     else:
---> 15         app.append ('non-free')
     16 apps_data[0].append('free_or_not')
     17 print(apps_data[:6])

AttributeError: 'str' object has no attribute 'append'

Hi @temitayoadeyemi,

The problem occurs in the first line of your for loop.

You are calling the list at index position one of the apps_data list of lists.

for app in apps_data[1]: # You are missing a colon directly after the 1

What you wanted to do was call all lists in the list of lists except the first one.
It’s a simple fix you just forgot to put the : after the 1

for app in apps_data[1:]: # see how there is a colon inside and outside of the square brackets

This will call everything from index position 1 (the second element) to the end of the list.

Let me know if you want more of an explanation.

Good Luck!

1 Like

It worked! Thank you very much.