Printing out a gage in the console with Python

#!/usr/bin/python3

import math, time

def gauge(size, position):
        print("Size: ", size, "Position: ", position)
        block = (size -2) / 100
        print("Block: ", block)

        filled = block * position;

        print("Filled blocks: ", filled)

        print("Filled blocks: ", math.floor(filled))

        print("[",end="");
        for i in range(1,(size -2)):
                if i < filled:
                        print ("#", end="");
                else:
                        print (".", end="");
        print("]");


for i in range(1,100):
        print('\033[s', end ='');
        gauge(75,i)
        print('\033[u', end = '');
        time.sleep(.1)
Dette indlæg blev udgivet i Python. Bogmærk permalinket.