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

how to print loading with dots appearing and disappearing

I want to create a python script that print loading with dots appearing 1 by 1 and disappering them 1 by 1. I know how to disappear all of them but I want them them to go back 1 by 1.

Here is the code:-


for x in range(5):
    for y in range(4):
        dot = "."*y
        loading = (f"Loading {dot}")
        print(loading + "   ", end = '\r')
        time.sleep(1)

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 :

I implemented the part that outputs dots in your code by making it a function.

import time

def dotmove(n):
    dot = "."*n
    loading = (f"Loading {dot}")
    print(loading + "   ", end = '\r')
    time.sleep(1)

for x in range(5):
    for y in range(4):
        dotmove(y)
    for z in range(2,  0, -1):
        dotmove(z)
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