同步操作将从 编程语言算法集/Python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
"""https://en.wikipedia.org/wiki/Combination"""def combinations(n: int, k: int) -> int:"""Returns the number of different combinations of k length which canbe made from n values, where n >= k.Examples:>>> combinations(10,5)252>>> combinations(6,3)20>>> combinations(20,5)15504>>> combinations(52, 5)2598960>>> combinations(0, 0)1>>> combinations(-4, -5)...Traceback (most recent call last):ValueError: Please enter positive integers for n and k where n >= k"""# If either of the conditions are true, the function is being asked# to calculate a factorial of a negative number, which is not possibleif n < k or k < 0:raise ValueError("Please enter positive integers for n and k where n >= k")res = 1for i in range(k):res *= n - ires //= i + 1return resif __name__ == "__main__":print("The number of five-card hands possible from a standard",f"fifty-two card deck is: {combinations(52, 5)}\n",)print("If a class of 40 students must be arranged into groups of",f"4 for group projects, there are {combinations(40, 4)} ways","to arrange them.\n",)print("If 10 teams are competing in a Formula One race, there",f"are {combinations(10, 3)} ways that first, second and","third place can be awarded.",)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。