0

Python Code explaination

CAN SOMEONE PLEASE EXPLAIN THIS CODE TO ME FULL THOROUGHLY, I DO GET It A LITTLE BUT IM STILL NOT SATISFIED WITH WHAT I GET. A VERY THOROUGH EXPLAINATION IS HIGHLY APPRECIATED. [ P.S I DONT KNOW WHY MY KEYBOARD IS WRITING UPPER CASE. SORRY HAHA P.S.S CAPS LOCK IS OFF ] https://code.sololearn.com/c62DmYh3jrpX/?ref=app

5th Mar 2020, 5:00 PM
R Raza
R Raza - avatar
9 Answers
+ 5
Maybe copied from somewhere? (In that case, you should put into your code where you've got it from!)
5th Mar 2020, 5:56 PM
HonFu
HonFu - avatar
+ 4
R Raza this is actually simple but I'm not sure where your confusion is. Can you kind of explain what you know so we can fill in the gap of understanding. The code works fine and this can be seen as advertising more than a true question.
5th Mar 2020, 5:13 PM
BroFar
BroFar - avatar
+ 3
R Raza In the loop definition you say -1, range(99,0,-1). So it substracts every time 1 to your index beer_num for this reason it works. You don't need the new_num variable to work, it is redundant.
6th Mar 2020, 5:31 AM
GeraltdeRivia
+ 2
BroFar thanks. i do get the range and for functions, theyre not so hard to explain. what i fail to understand is that how the code actually works after the first else statement, thats when it starts to get confusing... Like; i get the first if statement and thats fine but how does the code compile the rest of it? i didnt write the print() for the No. of beers left after 99 but the code somehow got it and kinda proceeded? How? maybe ive a problem with the if/else understanding yet? i still feel like i didnt explain what i wanted to but hope you get me, lol. and no its not advertising :p
5th Mar 2020, 7:03 PM
R Raza
R Raza - avatar
+ 2
HonFu Oh the code i wrote myself, (learned it from another place, thought to try it here on SoloLearn) but i dont seem to understand what i wrote. surprised with the results tbh. hahah
5th Mar 2020, 7:04 PM
R Raza
R Raza - avatar
+ 2
R Raza It would work without the else part. What is the question? What did you want to achieve? Do you want to remove 2 beers in the same loop? Because it counts the same amount of beers when you substract 1 beer in the else part and then when is restarting the loop.
5th Mar 2020, 8:40 PM
GeraltdeRivia
+ 1
GeraltdeRivia i want to understand how the loop restarts over with one less number of beer after every 3 lines eventhough i never used a line of code like “print (new_num, word, “of beer on the wall)” please help.
6th Mar 2020, 1:39 AM
R Raza
R Raza - avatar
+ 1
Code Crasher wow thanks a lot man, such a readable code ❀... i can’t appreciate enough. Now i’m getting a little more hang of it thanks to you simplifying it. and yes, maybe i do need to study this code a little more. Thanks again
6th Mar 2020, 4:11 PM
R Raza
R Raza - avatar