change value when python is in infinite loop -
change value when python is in infinite loop -
can done in python? start print infinite loop , changing values in between loops.
x = 5 while ( true ): print x x = 3 # regain command of interpreter , set new value
expected output:
5 5 5 ...... 3 3 3
no, code have written not work. statement after non-terminating loop never executed.
try following:
x = 5 while true: if (some-condition): x = 3 print x
alternatively, utilize threading, , alter value of x in sec thread:
def changex(): global x x = 3 x = 5 import threading threading.timer(3, changex).start() # executes changex after 3 seconds in sec thread while true: print x
python
Comments
Post a Comment