Home > database >  For loop in for loop not executing right
For loop in for loop not executing right

Time:02-16

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)

CodePudding user response:

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

print("Loading"   "." * y   "   ", end='\r')

CodePudding user response:

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

Found the answer.

  • Related