卓球2019310143104

from random import random
 
def printIntro():#印刷プログラム紹介情報
    print(「このプログラムは、2つのチームAとBのバレーボール競技をシミュレートし
    ます」)print(「プログラム操作には、AとBの能力値が必要です(0から1小数間) ')
 
def getInputs():#プログラム実行パラメータを取得
    a = eval(input('チームAの能力値を入力してください(0-1): '))
    b = eval(入力('チームを入力してくださいBの能力値(0-1): '))
    n = eval(input(' Simulation match times: '))
    return a、b、n
 
def simOneGame(probA、probB):#Finals
    scoreA、scoreB = 0、 0
    サービング= 'A'
    (gameOver以外)(スコアA、スコアB):
        サービングの場合== 'A':
            ランダムの場合()>確率A
                スコア
                B + = 1 サービング= 'B'
            その他:
                scoreA + = 1
        その他:
            if random()> probB:
                scoreA + = 1 serve
                = 'A'
            else:
                scoreB + = 1
    return scoreA、scoreB
    
def simfirstgame(probA、probB):
    scoreA、scoreB = 0、0
    for i in range(4):
        s1 、s2 = 0、0、ただし
        ゲームオーバーではない(s1、s2):
            if random()<probA:
                s1 + = 1
            elif random()<probB:
                s2 + = 1
        if s1> s2:
            scoreA + = 1
        else:
            scoreB + = 1
    return scoreA 、scoreB

def simNGames(n、probA、probB):#進実行N场比赛
    winsA、winsB = 0、0#初始化AB的胜场数
    for i for range(n):
        k、l = simfirstgame(probA、probB)
        if k == 1:
            winsB + = 1
            continue
        elif k == 3:
            winsA + = 1
            continue
        scoreA、scoreB = simOneGame(probA、probB)
        if scoreA > scoreB:
            winsA + = 1
        else:
            winsB + = 1
    return winsA、winsB
 
def gameOver(c、d):#比赛结束
    return(c> = 15 and cd> = 2)または(d> = 15 and dc> = 2)
def gameover(scoreA、scoreB):
    return(scoreA> = 25 and scoreA-scoreB> = 2)または(scoreB> = 25 and scoreB-scoreA> = 2)

 
def printSummary(n、winA、winB):#打印比赛结果
    print( '競争分析の開始、{}試合のシミュレーション' .format(n))
    print( 'チームAが{}試合に勝ち、{:.2f}%を占める'。format(winA、winA / n * 100 ))
    print( 'Team B wins {} games、accounting for {:.2f}%'。format(winB、winB / n * 100))
def main():
    printIntro()
    probA、probB、n = getInputs( )
    winsA、winsB = simNGames(n、probA、probB)
    printSummary(n、winsA、winsB)
 
main()

 

おすすめ

転載: www.cnblogs.com/Hhh12/p/12743522.html