Print statement placement question


#1


How do you know where to put the print statement (indentation wise). I can usually figure out where to put the print statement for the problem i'm doing, because only one way will work to let me pass the lesson, but I don't actually know why?

Here is an example of print statements with two different indentations, can anyone tell me why they are placed where they are, and why they don't work with any other indentation? Thanks!!!!!


def grades_variance(scores):
    average = grades_average(scores)  
    variance = 0
    for score in scores:
        variance += (average - score) ** 2
    return variance / len(scores)
print grades_variance(grades)

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


#2

def grades_variance(scores):
    average = grades_average(scores)  
    variance = 0
    for score in scores:
        variance += (average - score) ** 2
        x = variance / float(len(scores))
    return variance

print grades_variance(ecores)

#3

def grades_std_deviation(variance):
    return variance ** 0.5

variance = grades_variance(grades)

print grades_std_deviation(variance)

#4

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