Error printing the list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Error printing the list

Error printing the list This is a code to print the Maximal and Minimal Product sum of a list, for example, The maximal product sum of list [1,3,5,9] is 69 and it's arrangement is [3,5,9,1] I.e (3×5)+(5×9)+(9×1)=6. Likewise the minimal is 27.. I have almost finished the code except the sorted array for maximum, i e [3,5,9,1] isn't printing and also for minimal ... not printing... I'm trying to assign the sorted list to variable 'finalist' But it doesn't go my way. https://code.sololearn.com/ckxA2JdHvFiX/?ref=app https://code.sololearn.com/ckxA2JdHvFiX/?ref=app

3rd Oct 2019, 4:21 PM
Thashreef Mohammed
Thashreef Mohammed - avatar
2 Answers
+ 3
Yeaah i just realized Diego my algorithm doesn't sort my array in all possible ways, except for the sequential order. And yeah, im able to print the sorted array using slice now. But can you tell me the reason why finalist=shuffle doesn't work but finalist=shuffle[:] aren't they the same thing?
4th Oct 2019, 9:01 AM
Thashreef Mohammed
Thashreef Mohammed - avatar
+ 1
1. Your algorithm doesn't work correctly. The maximal product of [1, 3, 5, 9] is 77, not 69. [1, 5, 9, 3] (1x5) + (5x9) + (9x3) == 77. 2. Change "finalist = shuffle" to "finalist = shuffle[:]". https://code.sololearn.com/c7q276eVCLwz/?ref=app
3rd Oct 2019, 10:40 PM
Diego
Diego - avatar