Something may be wrong in the "Functions Intermediate" Chapter 5

Screen Link: https://app.dataquest.io/m/316/functions%3A-intermediate/5/multiple-return-statements

Your Code: # INITIAL CODE
def iserror(func, *args, **kw):
exception = kw.pop(‘exception’, Exception)
try:
func(*args, **kw)
return False
except exception:
return True

def open_dataset(file_name=‘AppleStore.csv’, headerdel = True):
opened_file = open(file_name)
from csv import reader
read_file = reader(opened_file)
data = list(read_file)
if headerdel:
if iserror(float,data[0][0]):
del data[0]
return data
The answer may be something wrong. The question require us to use if statement to find out whether it has a header row and then remove that. but the answer just used the default argument. Althought I pass the final check, but the process is totally different, pls kindly help to check it again, many thx :slight_smile:

1 Like

Hi @xueming.bian1,

Instruction

Add an extra parameter to the open_dataset() function (already written in the code editor) such that it only returns data sets without header rows.

The instruction is asking us to make the function return data set without header by default using an additional parameter. That is why we are using a default argument here. So if we call, open_dataset(), the header is excluded. To include the header we have to call open_dataset(remove_header=False).

However, I agree with you, the sub-instruction is making it confusing:

  • If a data set has a header row, the function removes the header row before returning the data set.

I will get it logged.

Best,
Sahil

Yes! I just got confused with the same stuff. Initially it took time for me to understand and execute the code. Later i realized that the first point of sub instruction has created a confusion.

  • If the parameter indicates that data set has a header row, the function removes the header row before returning the data set.

Kindly look into this and do needful so that other learners will not face the same issue anymore.
Thanks for understanding.
Best
K!