6. just weight and see


#1

what am i doing wrong??

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)
    total = total / len(numbers)
    return total
def get_average(student):
    homework = average(student["homework"]) 
    quizzes = average(student["quizzes"]) 
    tests  = average(student["tests"]) 
    return (get_average['homework']*10) + (get_average['quizzes']*30) + (get_average['tests']*60)

my error message:

Oops, try again. get_average(alice) raised the following error: 'function' object has no attribute 'getitem'

please help


#2

Hi this line

    return (get_average['homework']*10) + (get_average['quizzes']*30) + (get_average['tests']*60)

you cant' call the function inside itself
You already saved the average inside some variable here..

homework = average(student["homework"]) 
quizzes = average(student["quizzes"]) 
tests  = average(student["tests"])

the they aske you to...
04. Multiply the 3 averages by their weights and return the sum of those three. Homework is 10%, quizzes are 30% and tests are 60%.
adn the 10% of homework you should mutliply it by 0.1 the same for the others (0.3, 0.6)


#3

please please i need help with this
def get_average(student):
homework=average(student["homework"])
quizzes=average(student["quizzes"])
tests=average(student["tests"])
return (get_average[homework]/.1) + (get_average[tests]/.6\
)+(get_average[quizzes]/.3)


#4

Hi you should read my post..


#5

i did and it didn't work for me sorry


#6

can you post your update code?


#7

sure here it is
def get_average(student):
homework=average(student["homework"])
quizzes=average(student["quizzes"])
tests=average(student["tests"])
return(get_average['homework']*0.1) + \
(get_average['quizzes']0.3) + (get_average['tests']0.6)


#8

Sorry but it's not like I alread said
this line

return(get_average['homework']*0.1) + (get_average['quizzes']0.3) + (get_average['tests']0.6)

YOU CANìT CALL THE FUNCTION INSIDE ITSELF SO THE

get_average['homework']*0.1

Should be

return homework * 0.1 ...

#9

i'm so sorry i did what you said and discovered that there where a problem because of a whitespace
this is the working code now it seems to be realy easy
def get_average(student):
homework=average(student["homework"])
quizzes=average(student["quizzes"])
tests=average(student["tests"])
return (homework*0.1) + (quizzes*0.3) + (tests*0.6)


#10

now there is another problem sorrly it is not working
def get_letter_grade(score):
if score >= 90:
return "A"
elif score >=80:
return"B"
elif score >=70:
return"C"
elif score >=60:
return"D"
else:
return "F"
print get_letter_grade(get_average(lloyd))


#11

Remove the indent to all this part

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

#12

it didn't work :(


#13

it worked i for got to remove the first space from the def get_letter_grade


#14

YOUR CODE SHOUL BE INDENT LIKE THAT

def get_average(student):
    ....
   return (homework*0.1) + (quizzes*0.3) + (tests*0.6)


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

#15

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