python - python中的概率计算
问题描述
我的问题是:我有 12 名球员,其中 3 名球员分别被命名为 A、B 和 C。12名选手分为2组,每组6人。我需要计算球员 A 和 B 在同一支球队中的概率,而球员 C 在另一支球队中的概率。数学不是我的强项,因为我很确定这不是一件很难计算的事情,但如果你能帮我解决这个问题,我将不胜感激。这是我到目前为止写的:
import random
playersnumb = 12
players = list(range(12))
A = random.choice([x for x in range(12)])
B = random.choice([x for x in range(12) if x != A])
C = random.choice([x for x in range(12) if (x != A) and (x != B)])
random.shuffle(players)
team1 = (players[:6])
team2 = (players[6:])
if A in team1:
print("Player A is in team 1")
else:
print("Player A is in team 2")
if B in team1:
print("Player B is in team 1")
else:
print("Player B is in team 2")
if C in team1:
print("Player C is in team 1")
else:
print("Player C is in team 2")
任何帮助表示赞赏。
解决方案
填写 1 个列表(共 6 个)的方式数 = 12!/(6!* 6!)comb(12,6)
填充六种列表的方法数(包括 A 和 B 而不是 C)= 9!/(4!* 5!)comb(9, 4)
另外,想要找到(不是 A 而不是 B 和 C)= 9!/(5!* 4!) comb(9, 5)
>>> from math import comb
>>> comb(12, 6)
924
>>> comb(9, 4) + comb(9, 5)
252
>>> 252 / 924
0.2727272727272727
推荐阅读
- javascript - 如何修改嵌套对象的属性?
- terraform - 运行 terraform 输出时无法获取输出
- java - cloudrun 因 find_vma 失败而失败
- javascript - 我的取消静音命令 discord.js v11.5 有问题
- python - 我无法在 VSCode 中一次打开多个文件
- node.js - 通过 mongoose Expresss 在 mongodb 中执行 push 和 pull
- python - 在python中加载文件夹的最大csv文件
- python - 在 Windows 任务调度程序中使用服务帐户运行 python 脚本几秒钟后终止
- python - Python 抓取 - 具有多个文本元素的表格
- android - 身份验证集用户名 kotlin Firestore