9/9 Unexpected Indent


#1

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

I get a message: 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. What does it mean?


#2

Would need the complete program to troubleshoot...

When you paste, use ``` before and another ``` after your code block to have it retain proper indentation and format, like so:

def my_func(foo,bar):
    funky_var = foo
    town_var = bar
    if funky_var == town_var:
        print "Abort!"
    else:
        funkytown = funky_var + town_var
    return funkytown

9/9 Unexpected Indent
#3

hello! did you fix problem?


#4

No, I'm still at an impasse. Is there something I overlooked? I'll try to properly paste with the indents.
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 * 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))

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


#5

If I indent the code you have submitted and run it, your functions works:

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 * 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"

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


print get_letter_grade(get_average(lloyd))    # returns "B" as expected


print "Lloyd's average is: " + str(get_average(lloyd))
print "Alice's average is: " + str(get_average(alice))
print "Tyler's average is: " + str(get_average(tyler))

# Returns
# Lloyd's average is: 80.55
# Alice's average is: 91.15
# Tyler's average is: 79.9

print get_letter_grade(get_average(lloyd))
print get_letter_grade(get_average(alice))
print get_letter_grade(get_average(tyler))

# Returns
# B
# A
# C

But I see you have no code to fulfil the two assignments for the lesson your help request is associated with (Lesson 11, 9/9):

Instructions
01. Finally, print out the result of calling get_class_average with your students list. Your students should be [lloyd, alice, tyler].
02. Then, print the result of get_letter_grade for the class's average.

You can use the formatting trick I mentionned in a previous post or you can use the button that looks like </> in the editor's toolbar. Both will have your pasted code rendered with proper indentation.

Sometimes errors are in the indentation itself so it is important to be able to see it to help troubleshoot properly. :smile:


"How Is Everyone Doing?"...don't know about ya'll, but i'm stuck
#7

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


#8

@denisaltroy

You'll notice that russharold does define his list of students and prints get_class_average and get_letter_grade for that average in his first post.

I have identical code to russharold, which is complete and executes correctly in the console. The only problem seems to be Code Academy's interpretation of the code and this Code Academy error message. The previous step 8/9 executed correctly and was passed by Code Academy and the console. The only lines added were the following:


class_students = [lloyd, alice, tyler]
class_average = get_class_average(class_students)
class_average_grade = get_letter_grade(class_average)
print "Class Average: %s" % class_average
print "Class Average Grade: %s" % class_average_grade

I also get an error identical message: "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."

The strange thing is, that if I comment out all of the new lines added since step 8, I get the same error message. This tells me that I am not reading a Python interpretor error message, but a Code Academy error message.

Still none the wiser. It may be a typo, or indentation problem, or unmatched brackets, but I cannot find the error.


#9

I fixed my error by changing the name of my students list to students instead of class_students. I'm not convinced that the error is anything more than pedantic nit-picking by the Code Academy program. The list being passed is a parameter and could be named anything under the sun.


#10

Hi @el_koder,

My guess is that when we hit "Save & Submit Code", our input probably gets parsed and analysed by a python script.

As you may or may not know, humans are slow and smart and computers are fast and dumb.

That being said: Never expect a computer to "understand" that what you are doing is "roughly the same" or even "better" than what it has asked you to do. Have a look at this post if you need a proof of that... :smile:

Now from your code I can see that you did not call your student list students but class_students instead.

If the python script analysing your code is looking for a variable named students... I'm sure you can see where this is going.

Your two print statements also are very nicely formatted and readability for a human eye is perfect. Unfortunately, the instructions where to simply print get_class_average on your student list, and then get_letter_grade of that get_class_average.

So...

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

:wink:

Many have finished this entire Python Introduction course so you can assume that every lesson "works".

Every time you'll stumble on an error, start by asking yourself "Am I doing exactly what this dumb machine is expecting me to do?" or more precisely "Am I giving it exactly what it is asking me for?"

Worked for me... :smile:


#11

In a regular class, with a human teacher evaluating assignments, I'd say you're right!

But the more you work with computer code, the more you will see that being scrupulous, precise, exact, perfectionist, punctilious, meticulous, fussy, fastidious and finicky are not flaws but actually qualities almost necessary to a programmer... :smile:


#12

Actually I have been a programmer for 35 years, and used many programming languages. Pedantic and nit-picking are not the same thing as scrupulous, precise, exact, perfectionist, punctilious, meticulous, fussy, fastidious and finicky. In my opinion the instructions are not written as clearly as many of the other steps previous to step 9/9.

The step 9/9 mentions the list "students". Students is also a pre-existing parameter variable of type list for the function get_class_average from step 8/9. The list variable and parameter variable of type list, in my opinion, should not have the same name, since they are different things entirely with the only the same type definition in common. Good practice would be to name the list variable containing content something more precise than just students, and leave the parameter variable with the more general name students.


#13

You have been coding for 35 years? :stuck_out_tongue:

There was no way for me to know so consider I meant no offense, I was just trying to be friendly and helpful!

Being French Canadian, I had to look up pedantic to be sure of its meaning and those are synonyms that were suggested by my friend Google! :smile:

Let's hope someone at Codecademy takes notes of your observations to improve the lessons.

In the meantime, to extend the fun... Step into the lab! :microscope:


#14

Hey there,

My code was also failing because I was calling

get_class_average( [alice, lloyd, tyler] )

with the list as so, but once I assigned the list to students
and called get_class_average(students) with the variable instead, my code passed. Go figure.


#15

i am a little lost with this part. Everything worked up until the print statement hmmmm. I know i am missing something. Any help would be appreciated.

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


#16

I get the same thing but i can not figure out what i am doing wrong!!!


#17

Hi @droughton,

Could you please post your entire code using the trick described here? It will help us help you :smile:


#18

there seems to be problem with the site interpreter.
I get the answer as "83.866667"
but the interpreter says

Oops, try again.
Did you remember to print the average of the class?
It looks like "83.8666666667" wasn't printed.

how can I get passed 9/9 ? please help


#19

Hi @faz, I'll be glad to help if you post your code using the trick described here. When you do, your code retains its proper formatting and it makes it quite easy for use to analyse it :slight_smile:


#20


#22