If you use VSCode or Pycharm you have Debug option to understand what is happening in each step. Let’s debug it:
a = 4
-
first loop:
x = 3and it’s add toavariable that was4, soa = 4 + 3and nowa = 7 -
second loop:
x = 4and it’s equal to 4, so it’s add toavariable that was7, soa = 7 + 4and nowa = 11 -
third and fourth loop:
x = 5andx = 6and they are smaller than 4, so nothing happen.
and finally a is 11
1
solved for loop and lists, new to python and programming [closed]