Students become teachers


Hey! I’m russian, so forgive me my language problems, I need help with code, it’s really strange problem, looks like there is subtraction somewhere…

Full code here:

lloyd = {
“name”: “Lloyd”,
“homework”: [90.0, 97.0, 75.0, 92.0],
“quizzes”: [88.0, 40.0, 94.0],
“tests”: [75.0, 90.0]
alice = {
“name”: “Alice”,
“homework”: [100.0, 92.0, 98.0, 100.0],
“quizzes”: [82.0, 83.0, 91.0],
“tests”: [89.0, 97.0]
tyler = {
“name”: “Tyler”,
“homework”: [0.0, 87.0, 75.0, 22.0],
“quizzes”: [0.0, 75.0, 78.0],
“tests”: [100.0, 100.0]

def average(numbers):
total = sum(numbers)
total = float(total)
return total/len(numbers)

def get_average(student):
homework = average(student[“homework”])
quizzes = average(student[“quizzes”])
tests = average(student[“tests”])
return homework0.1 + quizzes0.3 + tests*0.6
print get_average(alice)

def get_letter_grade(score):
score = int(score)
if score >= 90:
return “A”
elif score >= 80:
return “B”
elif score >= 70:
return “C”
elif score >= 60:
return “D”
return “F”
print get_letter_grade(get_average(lloyd))

def get_class_average(class_list):
results= []
print results
class_list = [lloyd, alice, tyler]
for student in class_list:
result = get_average(student)
return average(results)

Please can someone help me?

the get_class_average should be capable of calculating the class average for a class of any size (1, 2 or 3 students).

We can achieve this by providing a parameter to the function and then when we call the function we can provide different arguments, so why do you overwrite your function parameter?


I suggest using print statements to print out each step taken to obtain that result, so that you can compare to how you would have done it manually, thus letting you spot where it goes wrong and fix the part of the code that is responsible for that step. A good idea is to start somewhere in the middle of the process so that instead of printing out everything you can tell if the mistake was earlier or later than where you decided to have a look.
(And just because the result is lower doesn’t mean subtraction happened)


Ah! I’ve finally understand what did you mean))
I’ve dismissed class_list = [lloyd, alice, tyler] and now it’s working, thanks!
But now I don’t understand why does it working =((( How do function knowes what argument to take, if I didn’t explained to it what class_list is?


Your suggestion was right, thank you. I understand that there can’t be any subtruction, I just tryed to say, that result is such a little bit lower so it’s very very weird, looks like something odd happend, like subtraction)) So can you explain to me why does it happens? Why did function returns a result little bit lower for “alice” item? And why did this happens because of that I put a meaning for class_list?


In a certain way, it doesn’t. Functions only execute when called, so until the function is called the parameter is only a placeholder for the python interpreter.

Then when you call the function, you provide an argument for the parameter, this way the parameter knows what value it should have.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.