How is everybody doing


#1

PLEASE HELP - I CAN't GO ANY FURTHER THEN THIS -
KEEP GETTING THIS MESSAGE - Oops, try again. Did you remember to print the average of the class? It looks like "83.8666666667" wasn't printed.

MY CODE:
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 0.1 * average(student['homework']) + \
0.3 * average(student['quizzes']) + 0.6 * average(student['tests'])

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'
get_letter_grade = get_average(lloyd)
print get_letter_grade(get_average(lloyd))

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

students = [lloyd, alice, tylor]
print get_class_average(students)
print get_letter_grade(get_class_average(students))

    IF CAN'T GET PAST THIS - I AM OUT - I SIMPLY DON'T UNDERSTAND WHY THAT MESSAGE.

HELP -SO FRUSTRATING


#2

It says something wasn't printed.
Was it?

If not, then you'll have to look at the part of your code that was supposed to print it.

If it was printed, then maybe you printed it slightly differently and will need to compare what you printed to what the instructions are asking for


#3

it was an indentation problem - the last PRINT lines had to putem under def get_class_average(student)

This Python is full of bugs and so confusing - sometimes - the course is great though overall

Thanks for reply


#4

Sounds like the bug was yours in this case.
By making the observation that your code was indeed not printing anything, you were able to find that the print was placed in the wrong place and fix it.
Making observations and comparing them to our expectations is how all bugs are fixed, unless accidental.


#5

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

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return 0.1* homework + 0.3*quizzes + 0.6*tests

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))
print get_letter_grade(get_average(alice))
print get_letter_grade(get_average(tyler))

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

students = [alice,tyler]
print get_class_average(students)
print get_letter_grade(get_class_average(students))

this works for me, simply by removing llyod out of the student list..


#6

You spelled tyler wrong in that last students list


#7

lmao even the moderator couldn't pick that up. :v


#8

@harrychew123 @arcmaster20763 Hello ! So ive tried it with your version, included lloyd too and it works perfectly fine. I do have a question tho, silly one at this point tbh. Nonetheless...initially when i tried and got the same code i had used
students = ["lloyd', "alice", "tyler" ] . this showed error message as :

Traceback (most recent call last):
File "python", line 52, in
File "python", line 49, in get_class_average
File "python", line 27, in get_average
TypeError: string indices must be integers, not str

then changed to students = [lloyd,alice,tlyer] it works perfectly.
I dont understand as why when its in intergers it works. I mean, those are names not numbers. And all this while when making list with names its been with " " within the [ ] .


#9

because adding the ' or " makes it a string. names in the student list are referencing dictionaries. Honestly I don't know why it says integer though.