New to python, help with my program?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wyominggirl419
    New Member
    • Feb 2010
    • 1

    New to python, help with my program?

    This program is supposed to read in a list of numbers and compute the average and standard deviation.

    As it is now, it returns nothing. Any help would be greatly appreciated.

    Code:
    scores=raw_input('Type in scores on one line with a space between each one: ')
    
    values = scores.split()
    for i in range (len(values)):
        values[i] = int(values[i])
    
    def average(values):
        average=sum(values)/float(len(values))
        return average
    
    def standardDev(average, values):
        total = 0
        for i in values:
            total +=(average-i)**2
        standardDev= total/((len(values)-1)**.5)
        return standardDev
    Last edited by bvdet; Feb 20 '10, 05:11 PM. Reason: Add code tags
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    If you take a look at your code, you will see that you have defined two functions, average and standardDev, but you never actually called them!

    The code below shows you what you were missing:
    Code:
    def average(values):
        average=sum(values)/float(len(values))
        return average
     
    def standardDev(average, values):
        total = 0
        for i in values:
            total +=(average-i)**2
        standardDev= total/((len(values)-1)**.5)
        return standardDev
    
    scores=raw_input('Type in scores on one line with a space between each one: ')
     
    values = scores.split()
    for i in range (len(values)):
        values[i] = int(values[i])
    
    av =  average(values)
    sd = standardDev(av, values)
    print(sd)
    Now, to get rid of that pesky math error...
    Last edited by Motoma; Feb 21 '10, 01:24 PM. Reason: Forgot /b ?!?

    Comment

    Working...