1

I am trying to get the result for comb. But the following error follows. Can i get any suggestions to resolve the error?

import math

def chirp(n):
        l=[]     
        for i in range(3141):
        i1=i/10.
        s=math.sin(n*i1)
        l=l.append(s)
    return l
l1=chirp(10,1)
l2=chirp(20,1)

l3=chirp(40,1)
comb= l1+l2+l3
print comb

Error:

Traceback (most recent call last):
  File "test.py", line 17, in <module>
    l1=chirp(10,1)
  File "test.py", line 15, in chirp
    l=l.append(s)
AttributeError: 'NoneType' object has no attribute 'append'
Bob
  • 173
  • 1
  • 10
  • possible duplicate of [Why does \[1\].append(2) evaluate to None instead of \[1,2\]?](http://stackoverflow.com/questions/12201716/why-does-1-append2-evaluate-to-none-instead-of-1-2) – vaultah Jul 22 '15 at 13:24

2 Answers2

3

Change the line

l = l.append(s)

to just

l.append(s)

append mutates the list, so you don't have to look at the return value (which is None).

Benjamin Peterson
  • 19,297
  • 6
  • 32
  • 39
1

Well, you're passing chirp() two positional arguments... are you using , as a decimal?

import math

def chirp(n):
    l = []
    for i in range(3141):
        i1 = i/10.
        s = math.sin(n*i1)
        l.append(s)
    return l

l1 = chirp(10.1)
l2 = chirp(20.1)
l3 = chirp(40.1)
comb = l1+l2+l3
print(comb)

This works for me with no errors. Note the in-place use of l.append(s).