Working with Files check not passing

Question

Your code here

How come this is showing wrong on the editor?

import csv

wage_list = []
with open("input.csv","r+") as f:
    reader = csv.reader(f)
lines = 1
for x in reader:
    if lines > 1:
        wage_list.append(x)
    lines += 1

with open("output.csv", "r+") as g:
    writer = csv.writer(g)
    fields = ['name', 'wage']
    people_writer = csv.DictWriter(g, fieldnames=fields)
    people_writer.writeheader() # writes the fields as the first row

    for x in wage_list:
        i = 0
        people_writer.writerow({'name': x[i], 'wage': int(x[i+1]) * 15})
        i += 1

Sandbox URL

(be sure to remove this if your project contains private data!)

Hey Arbob, thanks for reaching out!

I’ve taken a look and the reason the check was not passing is because the second field in your output file was named wage, not wages. Since your script is correct and should pass the check, I have edited the check to be more lenient on field names.

Thanks for letting us know about this!

Best,
Lorraine

1 Like

Thanks :slight_smile:

1 Like