Just weight and see: Student Becomes the Teacher


#1

Errro: 4.0
Traceback (most recent call last):
File "python", line 39, in
TypeError: 'function' object has no attribute 'getitem'

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]
}

Add your function below!

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

numbers=[2,4,6]
print (average(numbers))

student=[lloyd,alice,tyler]

def get_average(student):
for i in student:
homework=average(i["homework"])
quizzes=average(i["quizzes"])
tests=average(i["tests"])
total=(homework*0.10)+(quizzes*0.30)+ (tests*0.60)
return (total)
print(get_average[student])


#2

get_average is a function and it is surrounded by parentheses not square brackets!


#3

here:

print(get_average[student])

get_average() is a function call, so it should have parentheses. Also, supply an actual student (lloyd, tyler or alice) as argument


#4

get_average(alice) raised the following error: string indices must be integers, not str

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]
}

Add your function below!

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

numbers=[2,4,6]
print (average(numbers))

student=[lloyd,alice,tyler]

def get_average(student):
for i in student:
homework=average(i["homework"])
quizzes=average(i["quizzes"])
tests=average(i["tests"])
total=(homework*0.10)+(quizzes*0.30)+ (tests*0.60)
return (total)
print(get_average([tyler]))


#5

tyler inside a square brackets [] ,you can directly pass it get_avaerage()?

hint**
when we pass a variable to a function, we don't use []

also..
You dont need for loop and
these i's.


#6

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