Why my code fails?

Screen Link:

My Code:

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

What I expected to happen:

What actually happened:

Value of moma is not what we expected.

Hi fellow DQ-students,

my code is not returning the expected result & I can’t see what is the problem. From my understanding everything is fine? Do I miss something?

Additional question about the structure of the question. Why do we first title case the gender/elements instead of a first check if the element is not empty & do the title case after that?

Thanks in advance.


You spelt “unknown” wrong.

1 Like

Hi @monorienaghogho thanks for your reply & your help. You are right I have a typo here. :slight_smile:

1 Like