LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

Python Data Analysis #2/11

Screen Link: https://app.dataquest.io/m/331/python-data-analysis-basics/2/calculating-artist-ages

‘’'Python
ages =
for elements in moma:
[quote=“2rinzin1, post:1, topic:551843, full:true”]

Screen Link: https://app.dataquest.io/m/331/python-data-analysis-basics/2/calculating-artist-ages

‘’'Python
ages =
for elements in moma:
date = row[6]
birth = row[3]
if type(birth) == int:
age = date - birth
else:
age = 0
ages.append(age)

final_ages =
for age in ages:
if age > 20:
final_age = age
else:
final_age = “Unknown”
final_ages.append(final_age)>


Error Message
Value of ages is not what we expected.


date = row[6]
    birth = row[3]
    if type(birth) == int:
        age = date - birth
    else:
        age = 0
    ages.append(age)
    
    
final_ages = []
for age in ages:
    if age > 20:
        final_age = age
    else:
        final_age = "Unknown"
    final_ages.append(final_age)>

Error Message
Value of ages is not what we expected.
more…

1 Like

Hi @2rinzin1:

Instead of

for elements in moma:

use

for row in moma:

Thank you it worked, I was under the impression that I could name any word for the iteration variable
Thank you

Yes, you can use any name for your iteration variable. However, you have to be consistent and call this variable with the same name every time you address it inside the loop. Hence, if you call it elements, you have to continue calling it elements everywhere inside the loop, for example:

for elements in moma:  
    date = elements[6]
    birth = elements[3]

If you decided to call it row, then continue calling it row every time you mention it inside the loop:

for row in moma:  
    date = row[6]
    birth = row[3]
2 Likes