Most common unisex name - practice problem

Screen Link:
https://app.dataquest.io/m/1010/conditional-statements-practice-problems/20/most-common-name

My Code:

from csv import reader
opened = open('dq_unisex_names.csv')
read = reader(opened)
data_set = list(read)

name = None
largest = 0
for row in data_set[1:]:
    if float(row[1]) > largest:
        largest = float(row[1])
        name = row[0]

What I expected to happen:
When I click run code, the output is correct and gives ‘Casey’

What actually happened:
An error message appears that the output is incorrect, meanwhile, the expected output after submitting my answer is the same as my output

- actual + expected

+ Casey

In the answers, None was assigned to the variable largest and added as a condition statement. And i assigned a zero instead.

Hi @karimyousrymohamedom, welcome back to the DQ community!

I like the way you solved this more than the solution did…nicely done! The only reason you are getting this error is because you did not print the result of name at the end of your code…that’s what the “+ Casey” means…it’s expecting this output but didn’t receive it. See what happens if you add print(name) to the end of your code.

Thanks a lot, it solved the issue, but i didn`t get it, is it something related to the platform itself or is it something about my code

It’s just what the system is expecting in order to check your answer; it’s expecting output to the console. Sometimes the exercise will ask you to store a value in a specific variable name and will simply check your code by checking the value of that variable.

In this case, we were free to use any variables we wanted and thus the system was checking your code by looking at what was being printed to the console. As a test, I cleared the console and just typed:

print("Casey")

and submitted that as my solution to this screen. It accepted that as a correct answer! :laughing:

In other words, it has nothing to do with your code but rather how the autograder is checking for a “correct” solution on this screen.

1 Like