13th Feb 2019, 6:40 PM
ANJALI SAHU
11 Answers
+ 5
Because the list elements are not numbers , so when you add "5"+" 2"+"3" you get "523" .
13th Feb 2019, 7:27 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 4
btw: You can simplify your while loop. while x: y += x.pop() The method pop removes the last element from the list and returns it - so exactly what you want here.
13th Feb 2019, 9:00 PM
HonFu
HonFu - avatar
+ 1
You are relatively far in your Python tutorial, so you must have read it. You should reread that chapter and experiment to get a feeling how it works. Simply spoken it works like if: with a condition, for example x<5. If x<5: do this or that. And while just means that as long as x < 5, the loop runs again and again and again, even forever - until (by the code inside the while block) x changes and is not <5 anymore. Im your example while x means: while there is anything at all in the list x...
14th Feb 2019, 4:01 PM
HonFu
HonFu - avatar
+ 1
honfu thanks a lot for clearing my doubt
14th Feb 2019, 4:26 PM
ANJALI SAHU
+ 1
My pleasure. :)
14th Feb 2019, 4:26 PM
HonFu
HonFu - avatar
0
why new x is an empty list???
14th Feb 2019, 3:36 PM
ANJALI SAHU
0
You always restore a one element smaller list in your x, and you do that 'while x'. So in the last round you store everything except the last element as before - but given a one element list [3] that is... nothing. [3] - last element == []
14th Feb 2019, 3:44 PM
HonFu
HonFu - avatar
0
I am not getting how while is working please some one explain me
14th Feb 2019, 3:53 PM
ANJALI SAHU
0
So you haven't written the code yourself?
14th Feb 2019, 3:56 PM
HonFu
HonFu - avatar
0
it was given in our book excercise
14th Feb 2019, 4:21 PM
ANJALI SAHU
0
Anyway, loops are really important (like 90% of what's in the tutorial), so be sure to review all of that and write your own practice codes!
14th Feb 2019, 4:26 PM
HonFu
HonFu - avatar