'Making a Progress Bar / Demo Download

So, i have made my own Progress Bar function and tried to implement it into a Download. It's not a real Download function, but that's fine for now. At the End of the Function it should display 100% and the full Bar, but a second percent sign appears behind the first one. It can't be added by line 17, as the string with the percent sign has a space in it. I don't know where it's coming from...

def ProgressBar(percent, size, doprint):
        sizedif = 100 / size
        output = "["
        space = "█"
        blank = "/"
        for x in range(math.floor(percent / sizedif)):
            time.sleep(0.001)
            output = output + space
        
        missing = size - math.floor(percent / sizedif)

        for y in range(missing):
            time.sleep(0.001)
            output = output + blank
        
        percentprint = str(round(percent, 1))
        output = output + "] "
        output = output + percentprint
        output = output + " %"

        if doprint == False:
            return output
        else:
            sys.stdout.write(output)
            sys.stdout.flush()

def DemoDownload(filesize, barsize):
x = 0
download = 0
while True:

    if x == 0:
        x = 1
    else:
        for y in range(len(writing)):
            sys.stdout.write("\b")
            sys.stdout.flush()
    
    writing = ""
    speed = randrange(8000,10000)
    download = download + speed
    percent = download / filesize * 100
    if filesize <= download:
        ProgressBar(100, barsize, True)
        break
    else:
        writing = ProgressBar(percent, barsize, False)
        sys.stdout.write(writing)
        sys.stdout.flush()
        time.sleep(1)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source