Bug in mission Python Data Analysis Basics, step 3

Screen Link: https://app.dataquest.io/m/331/python-data-analysis-basics/3/converting-ages-to-decades

Issue: No “Next screen” shown to pass the step and mark the course as completed

Details:

  • Refreshing does not help.
  • Copying the answer and pasting into empty lines do not bypass the step either.

Support ticket number: 36279.

Please help with this issue. Thanks.

Hi @vananh.dt102,

Welcome to the community! I have responded to your ticket #36279.

Best,
Sahil

Thanks! It works now. Hope that next missions won’t see the same bug :slight_smile:

1 Like

Hey Sahil,

Console still throws the error in multiple tasks since yesterday. I am not sure if it has to do something with any internal upgrade.

Would request you to check it again, Here is my code to the problem and the output seems good both for the previous and this question but throws the length error:

#final_ages
decades=[]

for age in final_ages:
    decade=str(age)
    if decade!='Unknown':
        length=len(decade)
        decade=decade[0:length-1]
        decade=decade+'0s'
1 Like

Hi @rohit13595,

Your code is almost correct! The only issue I am seeing is that you forgot to append the decade variable to decades list.

decades=[]

for age in final_ages:
    decade=str(age)
    if decade!='Unknown':
        length=len(decade)
        decade=decade[0:length-1]
        decade=decade+'0s'
    decades.append(decade)

Best,
Sahil

1 Like

I had the same issue. The problem is that the answer given throws up the error. The official answer needs to be changed to avoid confusion/error.

1 Like

Hi @bsgbrand,

That’s weird!

decades = []

for age in final_ages:
    if age == "Unknown":
        decade = age
    else:
        decade = str(age)
        decade = decade[:-1]
        decade = decade + "0s"
    decades.append(decade)

The solution code is not creating an error on my end. Can you please check it again?

Thanks,
Sahil

Hi Sahil
im not able to move forward. im getting below error. my code excatly same as data quest. where is the fault ?
code:

from csv import reader

# Read the `artworks_clean.csv` file
opened_file = open('artworks_clean.csv')
read_file = reader(opened_file)
moma = list(read_file)
moma = moma[1:]
# Convert the birthdate values
for row in moma:
    birth_date = row[3]
    if birth_date != "":
        birth_date = int(birth_date)
    row[3] = birth_date
    
# Convert the death date values
for row in moma:
    death_date = row[4]
    if death_date != "":
        death_date = int(death_date)
    row[4] = death_date

# Write your code below
for row in moma:
    date = row[6]
    if date != "":
        date = int(date)
    row[6] = date
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)

decades = [ ]

for age in final_ages:
    if age == "Unknown":
        decade = age
    else:
        decade = str(age)
        decade = decade[:-1]
        decade = decade + "0s"
    decades.append(decade)

error: after execution

Variables

decadeslist (<class ‘list’>)

  • actual + expected

Hi @pravinvijayan66,

Your code is correct based on the code we have used on the previous screens. However, final_ages variable used by dataquest on this screen is slightly different.

To make sure that your code is aligned with the expected values of this screen, just replace:
if age > 20: with if age >= 20: and your code will pass the answer checker.

from csv import reader

# Read the `artworks_clean.csv` file
opened_file = open('artworks_clean.csv')
read_file = reader(opened_file)
moma = list(read_file)
moma = moma[1:]
# Convert the birthdate values
for row in moma:
    birth_date = row[3]
    if birth_date != "":
        birth_date = int(birth_date)
    row[3] = birth_date
    
# Convert the death date values
for row in moma:
    death_date = row[4]
    if death_date != "":
        death_date = int(death_date)
    row[4] = death_date

# Write your code below
for row in moma:
    date = row[6]
    if date != "":
        date = int(date)
    row[6] = date
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)

decades = []

for age in final_ages:
    if age == "Unknown":
        decade = age
    else:
        decade = str(age)
        decade = decade[:-1]
        decade = decade + "0s"
    decades.append(decade)

I will also get this issue logged.

Best,
Sahil

1 Like

Thanks a lot. It is now working

1 Like

Hi,
I’m getting the same issue as the original issue posted here for Converting Ages to Decades. Was a solution ever suggested for that? My code was identical to the DataQuest answer, but I went as far as to copy and paste the DataQuest answer code. Got the same error in the decades list. DQ answer key is expecting a row to be “20’s” but the code produces “Unknown”. Can’t complete this part of the mission. Thanks!

Code:

decades = []

for age in final_ages:
    if age == "Unknown":
        decade = age
    else:
        decade = str(age)
        decade = decade[:-1]
        decade = decade + "0s"
    decades.append(decade)

Error:

   '40s',
   '50s',
   '20s',
   '20s',
   '60s',
-  'Unknown',
+  '20s',
   '30s',
   '60s',
   'Unknown',
   '50s',
   '40s',
   '40s',
   '40s',
   '20s',
   '60s',
   '40s',
   '40s',
2 Likes

Hi @ammiller985,

Welcome to the community!

This issue has been fixed. Can you please try again?

Let me know how that goes. :slightly_smiling_face:

Best,
Sahil