# How is everybody doing! Moderators Help pLease!

#1

``````Please moderators or anybody here HELP!!

it keeps giving error even though I follow everything step by step. Quick please, thanks in advance!!!
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(sum(numbers))
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
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:
get_average(student)
results.append(get_average(student))
return average(results)
students = [lloyd, alice, tyler]
print get_class_average(students)

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

Console :

File "python", line 50
^
SyntaxError: invalid syntax``````

Continuing the discussion from 9. How is everybody doing? Error:

#2

Read again error message. There is something wrong with this line:

``print get_letter_grade(get_class_average([lloyd, alice, tyler])``

Error indicator points at the end of this line. This usually means that there is an unclosed brace... yep, that's it, you have to add `)` to close call of `get_letter_grade`.

#3

this line:

``print get_letter_grade(get_class_average([lloyd, alice, tyler])``

take a look at the number of opening brackets (`(`) and closing brackets (`)`), they don't match

#4

just added the bracket but still doesn't work. now it says this
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

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

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

#5

did you take another look yourself before posting? Your function calls are inside the function, they should be outside the function

#6

yes. I have been on this for two days now. learned it by heart! posted in several discussions just accidentally forgot to put the bracket before. just whole code doesn't work. something is wrong not indentation or code i suspect

#7

the indention is wrong, the function calls are inside the function

#8

please paste the code so i know what it translate to. thanks in advance.

#9

function:

``````def test_function():
print "do something"``````

function call inside the function:

``````def test_function():
print "do something"
test_function()``````

function call outside the function:

``````def test_function():
print "do something"
test_function()``````

#10

I am so sorry. I an new in coding. But I don't see the difference in your pasted code. indentation or piece of code. could you be patient with me further and help me see it?

#11

test_function() indentation okay. let me try

#12

nothing works! I don't know what is wrong!

#13

These lines:

``````students = [lloyd, alice, tyler]
print get_class_average(students)

should not be part of the `get_class_average` function, right?

#14

def get_class_average(students):
----results = []
for student in students:
---- get_average(student)
results.append(get_average(student))
return average(results)
students = [lloyd, alice, tyler]
print get_class_average([lloyd, alice, tyler])

2)
students = [lloyd, alice, tyler]
print get_class_average([lloyd, alice, tyler])

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

#15

why do you have indention after this line:

``students = [lloyd, alice, tyler]``

? No need to have indent at the print lines

And please start using markup so we can actually see the indent of your code on the forum:

#16

after students = [lloyd, alice, tyler] I just press enter print line get indented therefore it lines up with students

I tried without that and still doesn't work

``````      students = [lloyd, alice, tyler]
print get_class_average([lloyd, alice, tyler])

or

``````     students = [lloyd, alice, tyler]
print get_class_average([lloyd, alice, tyler])

does not work. Neither!

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

console:

83.8666666667
Traceback (most recent call last):
File "python", line 50, in
NameError: name 'students' is not defined

#17

Ok, from the beginning. This is part of the code we have to work on:

``````def get_class_average(students):
results = []
for student in students:
get_average(student)
results.append(get_average(student))
return average(results)
students = [lloyd, alice, tyler]
print get_class_average(students)

The only thing that is wrong is the missing `)`. Let's add it:

``````def get_class_average(students):
results = []
for student in students:
get_average(student)
results.append(get_average(student))
return average(results)
students = [lloyd, alice, tyler]
print get_class_average(students)

Now, this code is correct and should be accepted, but there is one more thing to fix. `return` keyword terminates the function and that is why these lines:

``````    students = [lloyd, alice, tyler]
print get_class_average(students)

will not be executed. Solution is quite simple, we can move these lines from the function body to the main level by decreasing level of indentation:

``````def get_class_average(students):
results = []
for student in students:
get_average(student)
results.append(get_average(student))
return average(results)
students = [lloyd, alice, tyler]
print get_class_average(students)

#18

it worked!
Thanks man for patiently walking me through this code. is there a learned material you can direct me to so I could read about function and indentation?

For example, why students and prints need to be under vertically in the same line. What does inside the function or outside the function mean?

Thanks again for making it easier!

#19

I am going to be honest here, how did you manage to get this far in the course without understanding indention? It should be nearly impossible. As for function, they where explained in earlier exercise, go look at them.

The indent determines what is inside a function or if/else statement. Many program languages use curly brackets for it (`{}`), python uses indent (the amount of spacing from the beginning of the line till the code)