L.Johnson - 3 months ago 16

Python Question

`def multiplyNums(aList):`

for (i,j) in enumerate(aList):

newList = []

if i < (len(aList)-1):

newList = (aList[i] * aList[i+1])

x = print(newList,end=',')

else:

newList = (aList[i] * aList[i])

x = print(newList)

return x

Answer

Is it that you would like to produce a list which contains the value of each entry multiplied by the following value (and the last value squared)?

ie. [2,3,4] -> [2*3, 3*4, 4*4] ?

If so then I think you should probably do:

```
def multiplyNums(aList):
newList = []
for (i,j) in enumerate(aList):
if i < (len(aList)-1):
newList.append(aList[i] * aList[i+1])
else:
newList.append(aList[i] * aList[i])
return newList
print multiplyNums( [2, 3, 4] )
```