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

23rd Mar 2018, 12:02 PM
Vicky Kuo
Vicky Kuo - avatar
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))
23rd Mar 2018, 12:26 PM
Geo
Geo - avatar
+ 4
Thanks. You too â˜ș.
26th Mar 2018, 6:23 AM
Geo
Geo - avatar
+ 2
Big thanks!! :) have a wonderful day!
26th Mar 2018, 6:20 AM
Vicky Kuo
Vicky Kuo - avatar