Python小练习
一、打印进度条
import sys import time for i in range(101): sys.stdout.write('\r') #清空之前的打印 sys.stdout.write("%s%% |%s" %(int(i/100*100),int(i/100*100)*'#')) sys.stdout.flush() #由于系统缓存的原因,有时候可能进度条打印回一次打印完,所有需要每次打印好强制刷新 time.sleep(0.5)
二、打印随机数
import random checkcode = '' for i in range(4): current = random.randrange(0,4) if current != i: temp = chr(random.randint(65,90)) else: temp = random.randint(0,9) checkcode += str(temp) print (checkcode)
"一劳永逸" 的话,有是有的,而 "一劳永逸" 的事却极少