9/9 How is Everybody Doing? Error message befor resolving


#1



https://www.codecademy.com/en/courses/python-beginner-en-qzsCL/1/5?curriculum_id=4f89dab3d788890003000096


Oops, try again. One of the following is missing or broken when we tried to use it: alice, lloyd, tyler, students, get_class_average, get_letter_grade


I have resolved it. I am just sharing to state that all these variable or functions need to be stated to pass the test. Putting in list form:
alice
lloyd
tyler
students
get_class_average
get_letter_grade

Most people will missed out the students variable as it has been removed after exercise 5


Replace this line with your 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)
    avg=total/len(numbers)
    return avg
    
def get_average(student):
    homework=student["homework"]
    quizzes=student["quizzes"]
    tests=student["tests"]
    grade=0.1*average(homework)+0.3*average(quizzes)+0.6*average(tests)
    return grade

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))

students=[lloyd, alice, tyler]
def get_class_average(students):
    for student in students:
        total=0
        total=+get_average(student)
        return total
    mean=total/len(students)
    return mean
print get_class_average(students)
print get_letter_grade(get_class_average(students))


#2

Your answer is right . I copy and pasted it, but it is not done correctly how python would like it done, and that's where I am getting confused. I like this academy because all the help people give on the problems, and even if I don't understand what is going on I can compare my answer to someone who has it correct and see what I am missing. Then I can understand what I did wrong and fix it for future instances, i.e. : , indent spacing whatever.
On your def of average you inserted the avg=total/len(numbers) no where did python tell me to do that, but I see what you did so it didn't bother me, their is always another way, I can see that. On the get_average(student) you created your own variable grade and had it return grade python didn't say that either, but I see again you just simplified it, no problem I am still following you. On the def get_class_average(students): you created your own total and your own mean and all that stuff. I did what python asked me and got through all the examples. This one I can't seem to find the right answer to this problem and I don't know what I did wrong is why I am stuck. Yes you have the right answer, but I want to understand how you have the right answer.

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

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

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

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))

Above is my code and another thing to not on your code is you don't even have proper spacing, and that is making think is spacing important. I am not beating you up by no means.I apologize if I am coming off that way I am just trying to get a better understanding. any feed back to why my code doesn't work would be greatly appreciate. Or even why you did the function get_class_average different would help as well. Thank you for your time.


#3

First time I posted was above, and it didn't copy my formatting I apologize. For the sake of argument and I don't want to fill the screen up again. Let's assume that I have got all the indention correct, and all my formatting is correct. I am strictly talking about how to solve How is Everybody Doing.


#4

Actually @bgilmore1982 is incorrect, Your code gives an error message because you don't have a variable named students with lloyd alice and tyler as a list right after your last dictionary which is tyler like this,

tyler = {
    "name": "Tyler",
    "homework": [0.0, 87.0, 75.0, 22.0],
    "quizzes": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]
}

students = [lloyd, alice, tyler]

#5

As what bandit mention your students list should not be a string of students name as lloyd, alice, and tyler are already a variable.

Instead of students=["lloyd","alice","tyler"]
use students=[lloyd,alice,tyler]

I have tested with the changes and your code works.


#6

I would also like to share and mentioned that the solution I came out with was because I have inadvertently left out exercise 8/9 and hence don't have the result section.

This just shows that there are many different ways to get the same answer.


#7

Can't get rid of this error.
Traceback (most recent call last):
File "python", line 55, in
File "python", line 53, in get_class_average
File "python", line 29, in get_average
TypeError: list 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]
}
students = [lloyd, alice, tyler]

# Add your function below!
def average(numbers):
    total = sum(numbers) 
    total = float(total)
    total /= len(numbers)
    return total

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

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))

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

#8

Hi trumanjp, I tried running your code, but the variable "all_students" was not defined.

The second thing is
def get_class_average(students):
results=[]

for student in students:
    results.append(get_average(student))
return get_average(results)

Instead of get_average(results), it should be average(results).

Your code should work after that. Try it.


#9

Yes this was right. Thank you.


#10

Below is the code I've been working on. In all honesty I've confused myself in part 8 and 9. I'm receiving an error message in my console that says:

Traceback (most recent call last):
File "python", line 54, in
LookupError: unknown encoding: utf-8

Any help would be greatly appreciated

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

students=[lloyd, alice, tyler]

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"])*0.1
quizzes=average(student["quizzes"])*0.3
tests=average(student["tests"])*0.6

return homework + quizzes + 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"

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))


#11

Assume that all indentations are in place and that the only addition is the two print statements at the bottom along with the students list.


#12

Hi dappad, I attempted to run your code with all the required indents. It did not give any problems. Perhaps you want to recopy your code with the indents to this forum so that we all can take a look. It could be an issue with the indent.


#13

Haha thanks terajumper57375. Its always when you ask for help that things want to start working properly. Just run the exact same code with no changes to indentation and it went through.


#14

made this code for the last step. I am getting the error
Traceback (most recent call last):
File "python", line 54, in
File "python", line 51, in get_class_average
File "python", line 28, in get_average
TypeError: string indices must be integers, not str.
what am i doing wrong here?

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

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

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:
results.append(get_average(student))
return average(results)
students = ["alice", "lloyd", "tyler"]
print get_class_average(students)


#15

See @bandit and my reply to @bgilmore1982 above.

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


#16

Hey terajumper. I seem to have the exact same code as the people who got it resolved but i just cant seem to get it working. So kindly help me with this as i post my entire code below. Thanks.

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

students=[lloyd, alice, tyler]

def average(numbers):
from math import *
total=sum(numbers)
total=float(total)
total=total/len(numbers)
return total

def get_average(student):
homework= average(students["homework"])
quizzes= average(students["quizzes"])
tests= average(students["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"

result= get_letter_grade(get_average(lloyd))
print result

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))

Hope it shows up with all the indentations as well.


#17

Nah indentations dont seem to be showing up. For now kindly just help me with the code.


#18

I keep getting a "One of the following is missing or broken when we tried to use it: alice, lloyd, tyler, students, get_class_average, get_letter_grade" error on my code, I don't understand 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]
}
students=["alice","lloyd","tyler"]

Add your function below!

def average(numbers):
total= sum(numbers)
total= float(total)
return total/len(numbers)
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)
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"
def get_class_average(students):
results = []
for student in students:
avg = get_average(student)
results.append(avg)
return average(results)
print results
print get_class_average(students)
print get_letter_grade(get_class_average(students))


#19

Look at your code starting after "for student in students:"
I had the same problem and realized that I had the same problem just appended the list by calling the original function instead of creating the avg variable. Hope this helps.


#20

tried almost similar code it shows error