For a game I am writing in Python 3.6.5, I made a text-based animation to indicate the passage of time (when chopping a tree or mining a rock, etc). I did a lot of trial and error to get the output how I wanted it, however it seems like I went about it in an overly-complicated way. I was wondering if there is a more efficient way to write this.
import os import time def progress_bar(text,secs): bar = '[' c = 0 #used in sum method to determine number of Xs in bar for i in range(0,11): print(text+'\n') bar = bar.replace(' ','') #get rid of previous spaces added to bar num_of_X = sum(c == 'X' for c in bar) #get number of Xs (progress) for x in range(0,(10 - num_of_X)): #Fill remaining space after Xs bar += ' ' print(bar + ']') bar += 'X' time.sleep(secs) os.system('cls' if os.name == 'nt' else 'clear') #clears terminal input('Loading complete!') progress_bar('Enter Your Text Here!',0.15)