Code works but nothing displays in the output monitor


#1



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

When I run this code I get a message saying the code was successful however the class average is not being displayed in the output screen. Instead the output screen says None.

Shouldn't the class average be displayed when the code 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]
}
students =[lloyd,alice,tyler]
# 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 0.1*homework+0.3*quizzes+0.6*tests
    
def get_letter_grade(score):
    if score>= 90.0:
        return "A"
    elif score>= 80.0:
        return "B"
    elif score>= 70.0:
        return "C"
    elif score>= 60.0:
        return "D"
    else:
        return "F"
        
def get_class_average(students):
    results=[]
    for n in students:
        results.append(get_average(n))
        
    return average(results)


#2

Is there any part of your code that says to display anything?


#3

You aren't printing anything to the screen, but the assigment doesn't want you to print anything anyway


#4

Ok, so what does the 'return' command do?


#5

It just returns the value


#6

But where does it return the value to? I don't understand what is happening when a value is returned if it is not displayed to the console.


#7

When a something is returned it is given back.

Simply put, think of it as a pitcher and catch in baseball.

The pitcher will throw the ball on command every time.

Now as the coach if you failed to put a catcher in the right place the ball will not be caught.

So when you tell your pitcher to throw to you, ensure you have a catcher lined up.

Now lets put this into practice.

Python Code: With out a catcher!

def no_catcher():
    return True

no_catcher()

As you can see nothing is displayed, but the function did throw the "ball."

Now lets put the catcher there.

Python Code: We found our catcher!

def pitcher():
    return "Ball"

def catcher(catch):
    print(catch)

throw = pitcher()
catcher(throw)

I hope this analogy helps you a tad. As you learn more about programming you will find more interesting ways you can "throw" and "catch" your ball.

If you still have any questions feel free to ask.