Deviation - green tick but no print


#1

https://www.codecademy.com/en/courses/python-intermediate-en-7mgOa/2/1?curriculum_id=4f89dab3d788890003000096

I followed the instructions step by step. I got the green tick but it doesn't print the result.

#computing standard deviation
def grades_std_deviation(variance):
    return variance**0.5
    variance = grade_variance(grades)
    print grades_std_deviation(variance)


#2

Your code should be indented in this manner for proper control flow,

def grades_std_deviation(variance):
    return variance ** 0.5
variance = grades_variance(grades)
print grades_std_deviation(variance)

#3

Ok... but I don't understand why. Could you please explain?


#4

Control flow is the order in which individual statements, instructions or functions are executed or evaluated. If your code is badly indented then it will be badly evaluated resulting in an error. :slight_smile:


#5

Hi @aviss ,

Specifically, the problem that @bandit corrected was that you had these two statements indented, which made them part of the grades_std_deviation function ...

    variance = grade_variance(grades)
    print grades_std_deviation(variance)

That is one of the reasons that they did not execute. To get statements that are part of a function to execute, the function must be called. However, in this case, even calling the function would not have caused those statements to execute, because they were positioned after a return statement, which causes function execution to terminate, and then passes control back to where the function was called.


#6

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