Moma returns as empty error

Link: https://app.dataquest.io/m/351/cleaning-and-preparing-data-in-python/5/string-capitalization

What am I doing wrong here?

My code returns error upon submission whereas the answer code submits successfully

My code:

for row in moma:
    gender = row[5]
    gender = gender.title()
    if not gender:
        gender = "Gender Unknown/Other"
    row[5] = gender
    
    nationality = row[2]
    nationality = nationality.title()
    if not nationality:
        nationality = "Nationality unknown"
    row[2] = nationality

Error: moma is shorter than expected
moma = [ ]

Answer

for row in moma:
    # fix the capitalization and missing
    # values for the gender column
    gender = row[5]
    gender = gender.title()
    if not gender:
        gender = "Gender Unknown/Other"
    row[5] = gender

    # fix the capitalization and missing
    # values for the nationality column
    nationality = row[2]
    nationality = nationality.title()
    if not nationality:
        nationality = "Nationality Unknown"
    row[2] = nationality
3 Likes

Hi @immanuel.ajay.r,

Welcome to the community!

I just checked your code on my end and it is not producing that error. Therefore, this must be a technical glitch. Can you please reload the page and try again?

Let me know how that goes.

That aside, there is a typo in your code:

Please change u to U.

Best,
Sahil

3 Likes

I am having the same problem (exercise 5 - string capitalization). I even changed my code to match the answer but to no avail.

1 Like

Hi @strawberryicemint042,

Can you please share with us the code you have used?

Thanks,
Sahil

1 Like

thank you for your quick response and help. I replaced my own code with the answer provided:

for row in moma:
gender = row[5]
gender = gender.title()
if not gender:
gender = “Gender Unknown/Other”
row[5] = gender

nationality = row[2]
nationality = nationality.title()    
if not nationality:
    nationality = "Nationality Unknown" 
row[2] = nationality

my code was slightly different:

for row in moma:
gender = row[5]
nationality = row[2]

gender = gender.title()
nationality = nationality.title()
if not gender:
        gender = "Gender Unknown/Other"
row[5] = gender

if not nationality:
        nationality = "Nationality Unknown"
row[2] = nationality

and i get the following error: Your code run has timed out.
This could be caused by writing an infinite loop, or an issue with our system.
Issue still persisting? Check our status page, or read about how to troubleshoot this error.

1 Like

the problem has been solved. i resubmitted my answer a few hours later and the error disappeared. thank you :slight_smile:

2 Likes

Glad to know it has been resolved @strawberryicemint042

1 Like