I'm brand new to coding and python. Could someone tell me what is wrong with my code?

def getlist():
     lst=[]
     answer1 = raw_input ("Would you like to add a number to create your mean value? y/n")
     if (answer1 == "y"):
          x = input ("Your number:")
          lst = lst + [x]
     return lst

def mean(l):
   return float(sum(l))/len(l)

a=mean(getList())
print a

I use python 3.0 and your modifying code works fine:

def getList():
     lst=[]
     answer1 = input ("Would you like to add a number to create your mean value? y/n")
     if (answer1 == "y"):
         while True:
            x = input ("Your number:")
            if not x: break
            lst = lst + [x]
     return lst

def mean(l):
    s = sum([ int(x) for x in l])
    return float(s/len(l))

a=mean(getList())
print (a)

you defined getlist() with lowercase letter 'l' and below used it with uppercase letter 'L'. Python is case-sensitive language. :)

I would do like this for your example, it shows the 'mean' when you just press enter with no input.

def getlist():
    lst = []
    x = None
    while x != '':
        x = raw_input('Your number:')
        if x:
            lst.append(int(x))
    return lst

def mean(l):
   return float(sum(l))/len(l)

a = mean(getlist())
print a

Cheers and Happy coding

This article has been dead for over six months. Start a new discussion instead.