''' python实现发红包 ''' def hong_bao(money,num): ''' 模拟红包 :param money:总钱数 :param num: 份数 ''' import random ret = random.sample(range(1,money*100),num-1) ret.sort() ret.insert(0,0) ret.append(money*100) for i in range(len(ret) - 1): yield (ret[i+1]-ret[i])/100 ret = hong_bao(100,5) for i in ret: print(i)