Python defined function f(*x) failed quiz question

Question:

I’m coursing Python applied for Data Science in CognitiveClass.ai, i’m at the functions module and did not understand why I failed answering this function-related question.

This is python 3 in a jupyter lab. I thought this code had a mistake but i failed.

This is the question:

What is the value of c after the following block of code is run ?

def f(*x):
    return sum(c)

a) Return the total of a variable amount of parameters
b) Return the total of a list return the total of a list
c) The function is not valid

I chose letter c and then B but without success. Letter A is the answer.

I’ll be very glad if someone can explain me why did I fail?

kalhan Koul :
For that you need to understand that in the definition of the function def f(*x): notation * means if unknown number of arguments variables are there then then return sum(c) will return the total number of arguments passed. Hence Answer A is valid. It was test of comprehension of question

Asked By: Robert Chang

||

Answers:

I don’t know, there might some error with the system. Option a is definitely not the right answer as I too had selected (a) in my first attempt. The function is invalid and the answer should be (c). In my second attempt (following the logic given in some of the comments above) I selected (c) and it came correct. Which it should as the function doesn’t initialise c anywhere in the body.

def f(*x):
   return sum(c)

complete the function  f  so that it returns the product of  a  and  b  , you the next cell to test the function

Gives the above error. Similar error is also given when replacing c with x . The function is incomplete and invalid.

Answered By: Annie Chakraborty
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.