模拟体育竞技分析
1)模拟体育竞技分析:(不同学号选做不同题目,必做题)
a.采用乒乓球比赛规则(学号尾号为0,1,2,3同学必做及格题)。
(即:一局比赛:
在一局比赛中,先得11分的一方为胜方;10平后,先多得2分的一方为胜方。
一场比赛:
单打的淘汰赛采用七局四胜制,双打淘汰赛和团体赛采用五局三胜制。
from random import random
class bisai(object): def __init__(self, nlA, nlB, n): self.nlA = nlA self.nlB = nlB self.n = n self.dfA = 0 self.dfB = 0 self.slA = 0 self.slB = 0 self.scA = 0 self.scB = 0 def bsai(self): qquan = 'A' for i in range(self.n): #重置比分 self.slA = 0 self.slB = 0 while not self.slA==4 or self.slB==4: #重置得分 self.dfA = 0 self.dfB = 0 while not self.dfA==11 or self.dfB==11: if qquan == 'A': if random()<self.nlA: self.dfA += 1 else: qquan = 'B' else: if random()<self.nlB: self.dfB += 1 else: qquan = 'A' #先到11分获胜,如果出现10平先多积两分者获胜 if self.dfA >= 11 and self.dfB < 10: self.slA += 1 break elif self.dfB >= 11 and self.dfA < 10: self.slB += 1 break #出现10平先多积两分者获胜 elif self.dfA == 10 and self.dfB == 10: while not self.dfA==12 or self.dfB==12: if qquan == 'A': if random()<self.nlA: self.dfA += 1 else: qquan = 'B' else: if random()<self.nlB: self.dfB += 1 else: qquan = 'A' if self.dfA >= 12 and self.dfB < 12: break elif self.dfB >= 12 and self.dfA < 12: break #先积两分者获胜 if self.dfA >= 12 and self.dfB < 12: self.slA += 1 break elif self.dfB >= 12 and self.dfA < 12: self.slB += 1 break #七局四胜 if self.slA >= 4 and self.slB < 4: self.scA += 1 break elif self.slB >= 4 and self.slA<4: self.scB += 1 break
def main(): A = eval(input()) B = eval(input()) n = int(input()) b = bisai(A, B, n) b.bsai() print(b.scA, b.scB) print("A胜率{:.2f}%".format(b.scA/b.n*100)) print("B胜率{:.2f}%".format(b.scB/b.n*100)) if __name__ == '__main__': main()

 
 
 
 
 
 
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号