预测球队比赛成绩

       竞技体育是指在全面发展身体,最大限度地挖掘和发挥人(个人或群体)在体力、心理、智力等方面的潜力的基础上,以攀登运动技术高峰和创造优异运动成绩为主要目的的一种运动活动过程。竞技体育是一种制度化、体系化的竞争性体育活动,具有正式的历史记载和传说,以打败竞争对手来获取有形或无形的价值利益为目标,在正式组织起来的体育群体的成员或代表之间进行,强调通过竞赛来显示体力和智力,在对参加者的职责和位置作出明确界定的正式规则所设立的限度之内进行。

       以下我们用代码预测羽毛球球赛球队比赛成绩:

一.羽毛球赛比赛规则

1. 21 分制,3局2胜为佳 
2. 每球得分制 
3. 每回合中,取胜的一方加 1 分 
4. 当双方均为 20 分时,领先对方 2 分的一方赢得该局比赛 
5. 当双方均为 29 分时,先取得 30 分的一方赢得该局比赛 
6. 一局比赛的获胜方在下一局率先发球

二.实例代码

from random import random
def printIntro():
    print("该程序的制作者为梁可乐(๑•ᴗ•๑)学号19")
    print("这个程序模拟两个选手A和B的羽毛球比赛")
    print("程序运行需要A和B的能力值(以0到1之间的小数表示)")
def getInputs():
    a = eval(input("请输入选手A的能力值(0-1): "))
    b = eval(input("请输入选手B的能力值(0-1): "))
    n = eval(input("请输入模拟比赛的局数: "))
    return a, b, n
def simNGames(n, probA, probB):
    WinsA, WinsB = 0, 0
    winsA, winsB = 0, 0
    for i in range(1,n+1):
        scoreA, scoreB = simOneGame(probA, probB)
        if scoreA > scoreB:
            winsA += 1
        else:
            winsB += 1
        if i%3==0:
            if winsA>winsB:
                WinsA+=1                
            else:
                WinsB+=1               
            winsA,winsB=0,0
    return WinsA, WinsB

def gameOver(a,b):
    if a==30 or b==30:
        return True
    if a>19 and b>19:
        if abs(a-b)==2:
            return True
    if a<=19 or b<=19:
        if a==21 or b==21:
            return True
    else:
        return False
def simOneGame(probA, probB):
    scoreA, scoreB = 0, 0
    serving = "A"
    while not gameOver(scoreA, scoreB):
        if serving == "A":
            if random() < probA:
                scoreA += 1
            else:
                scoreB +=1
                serving="B"
        else:
            if random() < probB:
                scoreB += 1
            else:
                scoreA += 1
                serving="A"
        return scoreA, scoreB
def printSummary(winsA, winsB):
    n = winsA + winsB
    print("竞技分析开始,共模拟{}场比赛".format(n))
    print("选手A获胜{}场比赛,占比{:0.1%}".format(winsA, winsA/n))
    print("选手B获胜{}场比赛,占比{:0.1%}".format(winsB, winsB/n))
def main():
    printIntro()
    probA, probB, n = getInputs()
    WinsA, WinsB = simNGames(n, probA, probB)
    printSummary(WinsA, WinsB)
main()

三、结果显示

 

转载于:https://www.cnblogs.com/howtobecool/p/10870290.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值