import sys import time for i in range(31): # 清空打印内容 sys.stdout.write(" ") # 控制输出样式 sys.stdout.write("%d%% | %s" % (int(i/30*100), int(i/30*100)*"*")) # 刷新缓存 sys.stdout.flush() # 控制打印速度 time.sleep(0.3)
#!/usr/bin/env python # -*- coding;utf-8 -*- import sys import time def jindu(fenzi, fenmu=100): rate = float(fenzi) / float(fenmu) rate_num = int(rate * 100) str_jindu = "*" * int(rate_num / 2) shuchu = " %s %d%%" % (str_jindu, rate_num) sys.stdout.write(shuchu) sys.stdout.flush() for i in range(1, 101): time.sleep(0.1) jindu(i)