Reputation: 173
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'
Upvotes: 1
Views: 89
Reputation: 20520
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
).
Upvotes: 3
Reputation: 346
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)
.
Upvotes: 1