Answer to Question #8833 in Python for Darcy

Question #8833
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;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS