python error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

python error

Hey sorry I have kinda zero python knowledge...but i know java.... can anyone explain this error in python? can anyone help me fix it for me please? ________________________________________________________________ def jumble(prices): s = len(prices) newPrices = [None]*s for x in prices: s = s - 1 newPrices[s] = x return newPrices _____________________________________________________ thank you! https://code.sololearn.com/c2St5D74N8fk/?ref=app

4th Apr 2020, 9:57 PM
KingDaniel2004
KingDaniel2004 - avatar
4 Answers
+ 8
The errors come from tabulations (tabulations are very important in Python, they replace the "{}" of many other languages). If we put the tabulations in the right places, we have: def jumble(prices): s = len(prices) newPrices = [None]*s for x in prices: s = s - 1 newPrices[s] = x return newPrices list=[1,9,3,7] print(jumble(list)) This code is like: list=[1,9,3,7] print(list[::-1])
4th Apr 2020, 10:40 PM
Mr.Fish
Mr.Fish - avatar
+ 7
And also the function argument must be a list, because int have not the len() attribute
4th Apr 2020, 10:44 PM
Mr.Fish
Mr.Fish - avatar
+ 5
Mirielle thanks!
5th Apr 2020, 3:10 AM
KingDaniel2004
KingDaniel2004 - avatar
+ 5
Mr.Fish thank you very much! Yap that was a part of cyber challenge question 😂 They added the python code and I had no idea how it's work😰
5th Apr 2020, 3:12 AM
KingDaniel2004
KingDaniel2004 - avatar