I am starting to study Python through an online course. Although I have worked in R
for a couple of years, and in general, I think the programming has many similar bases, there are notable differences. One of the most obvious ones I have noticed is the use, in Python
, of operators such as: + =, * = and / =. The following code, which I took from an exercise of the course that I comment has a couple of those operators:
n=100
number_of_times = 0
while n >= 1:
n /= 2
number_of_times += 1
print(number_of_times)
When one runs the code, the result in the console is 7. The point is that the exercise only asked to run the code and write down the result in the answer sheet, which does not have much complication.
However, I would like to know how to "reason" the program so that it gives 7, that is, how the code could be dissected step by step to arrive at that answer considering that a "while" is used.
I would like someone to explain to me or give me some reference about it.