L.Johnson L.Johnson - 2 months ago 8
Python Question

The argument is entered as a list (ie. [4,5,6]). But how can I get the output as a list and not just integers

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] )