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 = 3
and it’s add toa
variable that was4
, soa = 4 + 3
and nowa = 7
-
second loop:
x = 4
and it’s equal to 4, so it’s add toa
variable that was7
, soa = 7 + 4
and nowa = 11
-
third and fourth loop:
x = 5
andx = 6
and 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]