Part of the whole 8 - 11


#1

This is the error message

File "python", line 54
return average(results)
^
SyntaxError: invalid syntax

This is my function

def get_class_average(students):
results = []
for student in students:
results.append(get_average(student)
return average(results)indent preformatted text by 4 spaces

need help! I try indenting return aligned with def, with for and ever with 3 tabs and on the next like, no results!

Im not sure if its gonna keep the indentation, but 2 line - 2 tabs, 3 line - 2 tabs, 4 line - 3 tabs, 5 line (return) - 2 tabs!


#2

please ignore the: indent preformatted text by 4 spaces line !


#3

Please paste your whole code, select it and press Ctrl +Shift + C


#4

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):
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 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(lloyd)

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

I did ! i Actually did it the first time, cause you said it before to someone else, but for some reason it doesn't keep the indentations, it comes out like this! But ill send picture !


#5

If keyboard shortcut doesn't work you can try icon </> from the toolbar which is just above replay window. Remember to select pasted code

About your error, is it still the same:


#6

I'm not on my computer man, this is different software system, once im on my computer ill just get a picture,
i try this -->
def get_class_average(students):
return average([get_average(student) for student in students])

it worked , but im still gonna try to figure out , why mine didnt !


#7

http://www.codeskulptor.org/#user40_2A2DzYiSjA_1.py

Theres's my entire code with indentations !


#8

You miss ")" in line 57 after student. But I've tried this code and it didn't work for me...

Well but I tried all over again using this code:

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

And it worked.


#9

Yep, missing parenthesis, but for me this code worked


#10

Well if I look at it now again... It's the same. But this time it worked...

I've noticed already that sometimes I try exactly the same thing, but it will work after I reset the code and type in again everything. I guess it's me being unexperienced and not magic, but well.

I guess problem solved :wink:


#11

Yeah, it's worked now, i did reset the code, thanks !