随机发红包
作者:互联网
# 写一个发红包,接受两个参数:金额 个数 import random money = 200 num = 10 ret = random.sample(range(1, money*100),num-1) ret.sort() ret.insert(0,0) ret.append(money*100) lst = [] for i in range(len(ret)-1): money = (ret[i+1]-ret[i])/100 lst.append(money) print(lst)
import random lst = [] def lucky_money(money,num): 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): money = (ret[i+1]-ret[i])/100 lst.append(money) return lst lucky_money(100,3) print(lst)
import random def lucky_money(money,num): 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): money = (ret[i+1]-ret[i]) yield money/100 for money in lucky_money(200,10): print(money)
标签:money,random,ret,lst,num,发红包,100,随机 来源: https://www.cnblogs.com/libragyf/p/12264754.html