Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

(Python) Why is my while loop not working?

I have been working on an operating system inside of Python and I am starting off with the system booting code. I have a while loop that executes when the variable "Booting" = 1. Inside the while loop is a script that prints "Booting" then replaces that with "Booting.", then it gets replaced with "Booting.." and so on until it reaches "Booting….." which should make it reset to "Booting" and reset the cycle. Instead, it just stops at "Booting….." and doesn’t continue to reset the cycle.

Here is the code:

import time
import sys

Booting = 1

while Booting == 1:
 print("Booting")
 sys.stdout.write("\033[F")
 time.sleep(0.2)
 print("Booting.")
 sys.stdout.write("\033[F")
 time.sleep(0.2)
 print("Booting..")
 sys.stdout.write("\033[F")
 time.sleep(0.2)
 print("Booting...")
 sys.stdout.write("\033[F")
 time.sleep(0.2)
 print("Booting....")
 sys.stdout.write("\033[F")
 time.sleep(0.2)
 print("Booting.....")
 sys.stdout.write("\033[F")
 time.sleep(0.2)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

it does not erase the rest of the line, so you need to replace any existing variables you want to overwrite with spaces

try

...
print("booting    ")
...
print("booting.   ")
...

etc

(there are many ways to clear the line this is just one (@code provides another good alternative in the comments)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading