r/pythonhelp • u/an0nbrownchick • Feb 11 '21
HOMEWORK homework problem, i don’t understand what it’s saying. would this be equal to 0?
1
u/Akshaykadav Feb 11 '21
What this code will do is: It will add every number in the list except the 6
The 'num' variable is used to store your addition (result).
The 'val' variable stores individual value from the list and the value changes as the for loop iterates (completes one loop).
Now the if checks, if the number in the 'val' variable is 6 and if it is not, it adds that value in the 'val' variable with the 'num' variable.
So the num = num + val looks like, now is 0 at first 0 = 0 + 1 now num has 1 1 = 1 + val. It will add the next value and so on.
Hope you are able to understand. If you want to learn python check my channel out any feedback would be appreciated. https://youtu.be/rNoinGxYQZY
1
u/SuddenDragonfly4471 Feb 15 '21
Hey I have a homework problem I don’t understand either, how do I go about getting some help so my grade doesn’t falllllllll.
1
u/Reddit_Lore Feb 11 '21 edited Feb 11 '21
I think it’s 24. Num = 0 Num = 2 Num = 2+4 Num = 2+4+8 (skip 6) Num = 2+4+8+10
Final num = 24
Hope this helps!
Edit: sorry for my formatting. I think what the code is trying to say is while moving through the list, store that value in num and move to the next. As long as it is NOT a 6, add it to your current value in num.