Why can I not do this?? def get_class_average(students): results =  results.append(get_average(alice)) results.append(get_average(tyler)) results.append(get_average(lloyd)) return average(results)
Hi @klyhat ,
The reason why you should not write the
get_class_average function in that manner is that it will only work for a class composed specifically of
lloyd. If anyone, including Codecademy's submission correctness test (SCT), attempts to use it for a different class of students, it will not work correctly.
In general, design your functions for general use.
Okay understood, however, is it wrong or incorrect code? B/c I kept getting error.
Hi @klyhat ,
The posted function's code, by itself, does not contain any technical errors. But it does ignore its parameter,
students, which is allowed, but is not great function design.
Your code might execute, as long as there are three global dictionaries named
lloyd, in your preceding code, with the appropriate format, to be passed to a function named
get_average and that can be processed by that function. If any of those conditions are not met, or if there are any errors in portions of your code that have not been posted, there will be an error message.
In addition to that, Codecademy's submission correctness test (SCT) will issue a message of complaint, if it tries to use your function to process a list other than one that contains all three students,
lloyd. So, while your function's code might be correct in the view of the Python interpreter, in the context of the rest of your code, which has not been posted for our inspection, it will likely fail Codecademy's test, which is designed to determine whether it conforms to the exercise instructions.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.