I donno whats wrong in this.. can anyone help me


#1

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 = float(sum(numbers))
    return total/len(numbers)
    
def get_average(student):
    homework = average(student["homework"]) 
    quizzes =  average(student["quizzes"]) 
    tests =  average(student["tests"])
    """return homework
    return quizzes
    return tests"""
    return 0.10 * homework +  0.30 * quizzes +  0.60 * tests 
    
def get_letter_grade(score):
    if score >= 90:
        return "A"
    elif score >=80 and score < 90:
        return "B"
    elif score >= 70 and score < 80:
        return "C"
    elif score >= 60 and score < 70:
        return "D"
    else:
        return "F"
    
 return get_average(lloyd)
    
students = ["lloyd", "alice", "tyler"]

def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)
   print get_class_average(students)
   print get_letter_grade(get_class_average(students))

#2

are you sure your indention is right?

here:

students = ["lloyd", "alice", "tyler"]

you stored strings in your list, why?

lets see what happens we put this to the test:

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

print get_average("lloyd")

this will throw an error, you should supply the dictionary lloyd as argument, so your students list should contain dictionaries also, not strings

If you need more help, post an updated version of your code


#3

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 = float(sum(numbers))
return total/len(numbers)

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

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

return get_average(lloyd)

students = [lloyd, alice, tyler]

def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)
print get_class_average(students)
print get_letter_grade(get_class_average(students))

i edited that but it is throwing an error One of the following is missing or broken when we tried to use it: lloyd, alice, tyler, students, get_class_average, get_letter_grade


#4

For the sake of organization, can we place the students list in the data area of the source code, just after all the dictionaries that it references?

lloyd = {}
alice = {}
tyler = {}
students = [lloyd, alice, tyler]

#5

noo i found the error, my mistake is after get_letter_grade function instead of printing that i accidentally wrote return.. by the way thanks fr helping..


#6

Not as if I did, but if it makes ya' look...


#7

Hi I have added comments/description inside your original code sample(below) where you have to perform changes to run this properly.

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 = float(sum(numbers))
    return total/len(numbers)
    
def get_average(student):
    homework = average(student["homework"]) 
    quizzes =  average(student["quizzes"]) 
    tests =  average(student["tests"])
    """return homework
    return quizzes
    return tests"""
    return 0.10 * homework +  0.30 * quizzes +  0.60 * tests 
    
def get_letter_grade(score):
    if score >= 90:
        return "A"
    elif score >=80 and score < 90:
        return "B"
    elif score >= 70 and score < 80:
        return "C"
    elif score >= 60 and score < 70:
        return "D"
    else:
        return "F"

 """Instead of 'return' type 'print' and remove spaces from starting. """
 return get_average(lloyd)

""" Remove double quotes from the list students[] as they are dictionaries and not string. """
students = ["lloyd", "alice", "tyler"]

def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))
    return average(results)

""" Remove spaces before print statement and indent it correctly"""
   print get_class_average(students)
   print get_letter_grade(get_class_average(students))

#8

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