+ 1
Find the max product of 2 adjacent numbers in a list
If the list is L=[-4,-10,3,4,5,30], the max product of 2 adjacent numbers is 150. TypeError keeps showing up and saying âintâ object is not iterable as the following code. Iâm wondering how to revise this. To anyone who is willing to help me, thank you so much! hope you have a wonderful day! L=[-4,-10,3,4,5,30] def max_mul(L): for i in range(len(L)-1): m=L[i]*L[i+1] return max(m) max_mul(L)
3 RĂ©ponses
+ 4
The max() need an array but you put an integer in m. Try this :
L=[-4,-10,3,4,5,30]
def max_mul(L):
m = []
for i in range(len(L)-1):
m.append(L[i]*L[i+1])
return max(m)
print(max_mul(L))
+ 4
Thanks. You too âș.
+ 2
Big thanks!! :) have a wonderful day!