60 384
Assignments Done
98,1%
Successfully Done
In April 2018

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
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions