[Solved] Why doesn’t this python code run infinite times? [closed]


It has to do with how the program source code is interpreted. range(a) will be executed before the body of the loop, producing an iterable object which yields 3, 4, 5. a will be modified later but it will not affect range(a) cause it has already been executed. The following will do what you want, but it’s kind of a silly program now:

a = 3
i = a
while i < a:
   print(a, end = ' ')
   a += 1
   i += 1

solved Why doesn’t this python code run infinite times? [closed]