1 Star 0 Fork 1

Z先生/python_practise

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
25.微信红包分配.py 758 Bytes
一键复制 编辑 原始数据 按行查看 历史
Z先生 提交于 2020-04-04 22:41 +08:00 . random随机数练习
#微信发红包,金额随机,人数随机待设定,所以这两个因素可以作为变量来设置
#金额用money
#人数用people
#先定义一个函数,随机分配的方法函数
#思路:设定主程序,然后根据题目要求进行修改
#随机分配程序,主程序
import random
def people_shuffle(money,people):
result=[]
max_money=money//people*2
for i in range(people):
if money>1:
m=random.randint(1,min(money,max_money))
else:
break
money-=m
result.append(m/100)
return result
#调取函数用,基本没有问题
people=int(input('Please set the redpocket number:'))
money=int(input('Please set the red number:')*100)
print(people_shuffle(money,people))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Mr_Z11/python_practise.git
git@gitee.com:Mr_Z11/python_practise.git
Mr_Z11
python_practise
python_practise
master

搜索帮助