Showing indentation error


#1


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

 def get_average(student):
     homework=average(student["homework"])
     quizzes=average(student["quizzes"]
     tests=average(student["tests"])
     return 0.1*average(student["homework"])+\ 0.3*average(student["quizzes"])+ \0.6* average(student["tests"])


Replace this line with your code.


#2

Ok so to help you with your indention error can you either A.) take a screenshot of your code in your lesson so we can look at it in the format you have it in right now or B.) can you, like you did with your def get_average(student): part put your code between the sets of three ` marks. That way it will show your code in the format you have it in your lesson! :smiley:


#3


#4

So below I have a basic outline that is not the correct code but is the correct formatting you should strive to achieve in this lesson. You should be able to fix your indention problem based off of this.

def average(numbers):
    total = blah
    total = blah
    return blah
    students = blah
def get_average(student):
    homework = blah
    quizzes = blah
    tests = blah
    return blah

#5


#6

It would seem the problem now has to do with your return statement. I realize you have written like the example in this lesson has. However, I believe to get rid of your problem you should just have 0.1*homework + etc. instead of having 0.1*average(student[homework])+


#7

but its asking abt avg in instructions


#8

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 = float(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


#9

File "python", line 29
def get_average(student):
^
IndentationError: unindent does not match any outer indentation level


#10

kindly rply??????????????????


#11

Your function for average() looks like this:

def average(numbers):

    total= sum(numbers)
    total = float(total)
    total = float(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

It should, in fact, look like this:

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 float((homework * 0.1) + (quizzes * 0.3) + (tests * 0.6))

Notice the difference in syntax and indentation.


#13

ok y didnt we use for loop and
tell me the format behind homework=average(student["homework'])
y did we write student


#14

To understand why we use student, you must first understand why we use parameters.

As of defining the function, the program does not know whether student is a number, a string, a list, a dictionary, etc. As far as the program is concerned student could be anything. And the the program could care less. It's just a placeholder for whatever you pass into the function when you actually call it. In other words think of parameters like variables, whenever you call a function, the argument you pass into it becomes the value for student. For instance if you called:

get_average(lloyd)

You would essentially be telling the program to run get_average(student) except now, student = lloyd. Until a function is actually called, the parameters you have set are valueless placeholders. Once you call the function and pass in arguments for those parameters, they take on value and purpose. What I mean by this is, if you did the following:

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

get_average(lloyd)

Notice how I defined the function using student as a parameter and then I called the function using lloyd as an argument. This is telling the program to run the code within get_average(student) but replace all mentions of student with lloyd. Basically it does this:

homework = average(lloyd["homework"])
quizzes = average(lloyd["quizzes"])
tests = average(lloyd["tests"])

lloyd["homework"] is an identifier for the value of "homework" in the dictionary called lloyd.
lloyd["quizzes"] is an identifier for the value of "quizzes" in the dictionary called lloyd.
lloyd["tests"] is an identifier for the value of "tests" in the dictionary called lloyd.

This is why we use student as we do in the function.

As for why we don't use a for loop... well, there's really no need for one.


#15

return 0.1*homework+0.3*quizzes+0.6*tests or return float((homework * 0.1) + (quizzes * 0.3) + (tests * 0.6))
don't return 0.1*homework+\ 0.3*quizzes+ \0.6* tests.
you wrong \


#16

I already covered this in my previous posts. There is no need to repeat a solution to a problem that has already been addressed.


#17

also i think we should run a loop as well???coz we r accessing both dictionaries


#18

We are only accessing one dictionary at a time right now. If you are talking about dealing with the lists in the dictionaries (i.e. "homework", "quizzes", and "tests"), well you already took care of that when you defined average(). Your average() function returns the sum of all the numbers in a list divided by the list's length. This means that when you call:

homework = average(lloyd["homework"])

You are setting homework equal to the average of all the items in the "homework" list of the lloyd dictionary.

When you call:

quizzes = average(lloyd["quizzes"])

You are setting quizzes equal to the average of all the items in the "quizzes" list of the lloyd dictionary.

When you call:

tests = average(lloyd["tests"])

You are setting tests equal to the average of all the items in the "tests" list of the lloyd dictionary.


#19

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