Oops, try again. There seems to be something wrong with your code, see the console window for the error message!


#1



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


Oops, try again.
There seems to be something wrong with your code, see the console window for the error message!
File "python", line 50
for student in class:
^
SyntaxError: invalid syntax

can you check my code at the very end


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)
    num=total/len(numbers)
    return num
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    sumofthree = .1*homework + .3*quizzes + .6*tests
    return sumofthree
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"
        
aaverage = get_average(lloyd)
letter_grade = get_letter_grade(aaverage)
print letter_grade

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


#2

Quite some mix-up here! The class list from which you are looping for a student is not yet defined. Moreover, class is a keyword for creating classes in python. Loop for student in the students, which is your function parameter, as in the instruction.

Lastly, your indentation of the getclass_average_ function isn't right. :slight_smile:

See suggested code below

students = [lloyd, alice, tyler]

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

#3

Oops, try again. get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected
at the same position


#4

Please, post now edited code! :slight_smile:


#5

Can't get the reason of the problem
''Oops, try again. get_class_average([alice]) resulted in an error: list indices must be integers, not str''

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


#6

I would have loved to see your full code and well formatted. But, you need to make sure that the students list for which you are looping for student is defined.

The see this lines...Doesn't look good.

You will want to do

results.append(get_average(student))

instead! :slight_smile:


#8

cant get how to make code looks nice here.

my fool code looks like that:
https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/4?curriculum_id=4f89dab3d788890003000096


#9

Sorry for messing here with a comments.

Can't get how here to make code looks nice.

my fool code looks like that:
https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/4?curriculum_id=4f89dab3d788890003000096


#10

Supplying me a link to your URL page, will take me to mine. I will need your account details to see your own full code. You could use the "< / > " to format code and then copy and paste as the OP.

Thank you! :slight_smile:


#11

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