A Tweak to the Solution for Screen 2/11 in Mission 2 of Python Data Analysis Basics

Hi everyone!

As I was working my way through the Python Data analysis Basics course, I was stuck at screen 2/11 of “Calculating Artist Ages”. It seemed that although I had the same code as the answer provided, an additional level of check was missing: that the column “birth” had to be an integer data type as well in order to calculate the age of the artwork.

Answer from the course:
ages =
for row in moma:
birth = row[3]
date = row[6]
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)

My answer:
ages =

for rows in moma:
date = rows[6]
birth = rows[3]
if (type(date) == int) and (type(birth) == int):
age = date - birth
else:
age = 0
ages.append(age)

final_ages =

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

I decided to include this in my “if” logic in my code (written in bold above) and turned out that my answer was accepted!

Perhaps we could change the solution to facilitate future learners on their way through this mission:) Looking forward to learning from all of you as a beginner in Python!:slight_smile: