Why I get different result when I multiply index numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why I get different result when I multiply index numbers

nums = [4,7,3,1] for x in nums:   print(x * 2) Output 8 14 6 2 nums = [1,2,3] print(nums * 3) Output [1,2,3,1,2,3,1,2,3]

12th Dec 2022, 2:06 PM
William A Cruz Mendoza
William A Cruz Mendoza - avatar
2 Answers
+ 4
In the first case, you are multiplying each number from the list. In the second case you are multiplying to a list of [numbers] and it is repeated several times. Do you need help to fix it?
12th Dec 2022, 2:39 PM
Knight
Knight - avatar
+ 1
Thank you so much!!
12th Dec 2022, 2:44 PM
William A Cruz Mendoza
William A Cruz Mendoza - avatar