Get error when create variable - Summarizing Artwork Gender Data

Screen Link: https://app.dataquest.io/m/331/python-data-analysis-basics/9/challenge-summarizing-artwork-gender-data

My Code:

gender_freq={}
for row in moma:
    gender = row[5]
    if gender not in gender_freq:
        gender_freq[gender] = 1
    else:
        gender_freq[gender] += 1

for gender, num in gender_freq.items():
    template= "There are {n:,} artworks by {g} artists"
    output=template.format(g=gender, n=num)
output

What I expected to happen:
I expect when I create variable “output” and print it, it will be the same result as the answer

What actually happened:

'There are 791 artworks by Gender Unknown/Other artists'

I would like you to take some time and check out the following two examples -

a = [1, 2, 3]
for i in a:
    b = i + 1
    print(b)

and

a = [1, 2, 3]
for i in a:
    b = i + 1
print(b)

In both cases, first think what the output would be if you ran the code.

Then, run the code and see if it matches with what you initially thought.

Then compare the above two examples to your code and try to understand what’s happening. Feel free to ask follow-up questions about the above.

1 Like

Thanks so much, I got it now :slight_smile:

1 Like