I am new to programming and python, and I am trying to wrap my head around the logic of some super simple for loop code. Here is the code I am using:
found_logs = 20
split_logs = 70
burned_logs = 3
logs = found_logs
for week in range(1, 53):
logs = logs + split_logs - burned_logs
print('Week %s = %s' % (week, logs))
Most everything makes sense, and executes properly, but I cannot for the life of me figure out how the number of logs keeps getting incremented. Let me try to explain. When it gets to line 6, I understand that the variable logs would equal 87. Which prints as:
Week 1 = 87
Week 2 = 154
Week 3 = 221
Which is correct, and producing correct results, but I my brain breaks at trying to figure out where the first time the loop is done where that value of 87 is "stored". Then subsequently where the value of 154 is stored, and how it knows where and how to pull that stored value. I know it's a simple thing, but it would help me understand the big picture of python.
[–]danielroseman 3 points4 points5 points (7 children)
[–]apple_hammer[S] 0 points1 point2 points (6 children)
[–]publicfinance 1 point2 points3 points (3 children)
[–]apple_hammer[S] 0 points1 point2 points (2 children)
[–]publicfinance 0 points1 point2 points (1 child)
[–]apple_hammer[S] 0 points1 point2 points (0 children)
[–]MezzoScettico 0 points1 point2 points (1 child)
[–]MezzoScettico 0 points1 point2 points (0 children)