Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
ShadowPower
Lucky-money-simulator
Repository navigation
Code
Issues
1
(1)
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Lucky-money-simulator
/
LuckyMoneySimulator.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
39 lines (30 loc) · 1.55 KB
master
Breadcrumbs
Lucky-money-simulator
/
LuckyMoneySimulator.py
Copy path
Top
File metadata and controls
Code
Blame
39 lines (30 loc) · 1.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from 中文编程 import *
def 随机分配(红包列表):
for 索引, 当前红包金额 in 遍历索引和元素(红包列表):
随机增减金额 = 小数(随机生成一个实数(0, 浮点数(当前红包金额 - 小数('0.01')))).量化(小数('.00'))
当前红包金额 -= 随机增减金额
红包列表[索引] = 当前红包金额 # 将结果写回去
红包列表[整数(随机生成一个实数(0, 长度(红包列表)))] += 随机增减金额
洗牌(红包列表)
总金额 = 小数(输入('请输入总金额:')).量化(小数('.00'))
红包个数 = 整数(输入('请输入红包数目:'))
# 平均分配后,较大的那批红包的个数
大红包数 = 整数(总金额 * 100) % 红包个数
较大的那批红包金额 = 小数(总金额 / 小数(红包个数)).量化(小数('.00'), 向上取整)
较小的那批红包金额 = 小数(总金额 / 小数(红包个数)).量化(小数('.00'), 向下取整)
# 生成初始红包状态
普通红包 = []
for 当前编号 in 范围(红包个数):
if 当前编号 < 大红包数:
普通红包.append(较大的那批红包金额)
else:
普通红包.append(较小的那批红包金额)
拼手气红包 = 普通红包[:]
随机分配(拼手气红包)
# 输出分配结果
for 索引, 当前红包 in 遍历索引和元素(拼手气红包):
打印('第', 索引 + 1, '个红包:', 字符串(当前红包))
# 实现Decimal求和
打印('最终红包总金额:', 规约(lambda 甲, 乙 : 甲 + 乙, 拼手气红包))
# 暂停查看结果
暂停()
You can’t perform that action at this time.