2

I just wrote some code for a loading symbol that displays

Loading
Loading.
Loading..
Loading...

and then repeats this five times. My only problem is after it executes that loop once, it won't repeat. Here's my code:

import time
for x in range(5):
    for y in range(4):
        print("Loading"+"."*y,end='\r')
        time.sleep(1)
Selcuk
  • 57,004
  • 12
  • 102
  • 110
BattleCalls
  • 63
  • 1
  • 7
  • Does this answer your question? [Remove and Replace Printed items](https://stackoverflow.com/questions/5290994/remove-and-replace-printed-items) – Tomato Master Feb 16 '22 at 08:13

3 Answers3

7

If you overwrite Loading... with Loading it will not erase the extra three dots. Try

print("Loading" + "." * y + "   ", end='\r')
Selcuk
  • 57,004
  • 12
  • 102
  • 110
0

The problem is that your code is printing the line next line on existing line. To avoid this replace you code with this:-

import time
for x in range(5):
    for y in range(4):
        print("Loading"+"."*y,end='\r')
        time.sleep(1)
    print("\n")

Using a line break will print the code on the next line, not on the existing line. Thank you.

CodeWithYash
  • 223
  • 1
  • 15
0
import time
for x in range(5):
    if x != 0:
        print("")
    for y in range(4):
        print("Loading" + "." * y, end='\r')
        time.sleep(1)
    

This will print Loading 5 times.