# Help re: Part of the Whole (Learning Python 2)

So, the code for the function is posted below:

``````# Add your function below!
def average(numbers):
total = sum(numbers)
total = float(total)

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

if score >= 90:
return "A"
elif score >=80:
return "B"
elif score >=70:
return "C"
elif score >=60:
return "D"
else:
return "F"

``````

My questions have to do with the terms â€śnumbersâ€ť and â€śscoreâ€ť within the functions being defined: since we have not defined â€śnumbersâ€ť or â€śscoreâ€ť, how does the computer know what they are? Are these terms already part of the Python language?

score and numbers are parameters, they get there value from the argument at function call:

``````# defining function with parameter
def get_average(student):

# calling function with argument, the value for the parameter, lloyd in this case
get_average(lloyd)
``````

So parameters act as placeholders until there value from the argument(s) at function call

1 Like

Except with the function get_average(student), we already defined the list of students at the beginning of the exercise (which is not included in this panel of code, and which I assume is part of the overall code being run anywayâ€¦?)
That way the computer knows to look at the list of students for â€śLloydâ€ť or â€śAliceâ€ť and select their particular set of homework gradesâ€¦isnâ€™t that correct?
So by that logic, â€śscoreâ€ť should be defined somewhere as:
score = get_average_student) or something like that, no?

You got it completely wrong.

parameters donâ€™t need a value until you call the function, and then you provide argument(s) for the parameter(s):

``````def example(par):
print(par)

example('hello world')
example('foo')
example('bar')
example('baz')
``````

in the example above i define a function with a parameter named `par`, then i make a bunch of function calls in which i pass different string value/argumens to the parameter.

so for example here:

``````example('hello world')
``````

hello world gets assigned to `par` (under the hood):

``````par = 'hello world'
``````
1 Like

OK, understood.
One more question:
Is it necessary to put the return function on a separate line as in:
if score >= 90:
return â€śAâ€ť
elif score >=80:
return â€śBâ€ť

or can it just as easily be written on a single line, as in:

if score >=90: return â€śAâ€ť

?

python has a style guide:

https://www.python.org/dev/peps/pep-0008/

which recommends separate lines. A style guide is not mandatory, but its good practice to follow the style guide

1 Like

ok, fair enough!