what is wrong with this function
def newSequence(ns, n, d):
nValue = 1
for a in ns:
ns[a] -= n*xValue**d
return ns;
compiler error message
line 3, in newSequence
for i in ns:
TypeError: 'int' object is not iterable
1
Expert's answer
2012-04-28T11:08:13-0400
The compiler error message means that in your call of the function 'newSequence' the first argument 'ns' is an integer value, though the declaration of that function requires that 'ns' is a list.
Moreover, it seems that in the line ns[a] -= n*xValue**d instead of 'xValue' there should 'nValue'.
Finally, the loop iteration for a in ns: should be changed to for a in range(len(ns)):
So the resulting function must be of the form:
def newSequence(ns, n, d): nValue = 1 for a in range(len(ns)): ns[a] -= n*nValue**d return ns;
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment