#8 Part of whole alice isn't happy


#1



can someone please explain my mistake


Oops, try again. get_class_average([alice]) resulted in an error: can't multiply sequence by non-int of type 'float'


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
    
students = [lloyd, alice, tyler]  
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    weighted = ("homework"*.1)+("quizzes"*.3)+("tests"*.6)
    return weighted
    
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(lloyd)

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


#2

There's an operation that goes like this:

>>> [1, 2] * 3
[1, 2, 1, 2, 1, 2] # the sequence 1, 2 repeated 3 times

But if you change the 3 to 3.24 then how many times should the sequence be repeated? Therefore, only ints are accepted for this


#3

I'm a bit confused. Are you referring to the function get_average? That worked earlier. Should I change the .6 from that function to 0.6 and so on to make it an int? Thank you for your assistance.


#4

I'm referring only to the error message, nothing in your code.

To fix your code, you need to read/understand what the error message says is wrong, and then consider where you could possibly carrying such an action out.

You can also reproduce the crash to get a line number from Python's error message

But yes, that's the only place in your code where you use the multiplication operator. What kind of values are you multiplying by what other kind of value at that location?

P.S. late reply because I'm only watching for direct replies to me and mentions, not to any response in threads that I've replied to.


#5

Thank you can you please tell me how to reply directly to the person helping?
You have a couple of times.
thank you


#6

You just did


#7

ok got that I think I followed your advice. I appreciate your patience, I will understand this, failure is not an option for me. :slight_smile: Can you advise more?

ef average(numbers):
    total = sum(numbers)
    total = float(total)
    total =total / len(numbers)
    return total
    
students = [lloyd, alice, tyler]  
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    weighted = ("homework"*0.1)+("quizzes"*0.3)+("tests"*0.6)
    return weighted
    
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(lloyd)

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

Oops, try again. get_class_average([alice]) resulted in an error: can't multiply sequence by non-int of type 'float'


#8

I've replied to that, you'd need to ask questions/explain what's stopping you for me to have anything further to say about that


#9

I apologize for offending you.
\What I thought I was saying is that
I made the change that you recommended,
and I am still getting the same error message.
Did I misunderstand your direction.


#10

I didn't say that, just that it's the same situation, the one I did make suggestions about how to proceed. With no new information/questions there'll also be no new answers


#11

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