乒乓球模拟比赛规则代码解析

from random import random
def getInputs():

乒乓球规则是一局比赛中先得 11 分为胜,10 平时,先得 2 分为胜

一场比赛采用三局两胜,当每人各赢一局时,最后一局为决胜局

probA = float(input("请输入选手 A 的能力值(0-1):"))
probB = float(input("请输入选手 B 的能力值(0-1):")) return probA, probB
def simOneGame(probA, probB):
scoreA, scoreB = 0,0
serving = 'A'
i=1
while not gameOver(scoreA, scoreB):
serving = switchServing(i, serving)#11,12行和33行def switchServing的关系
i += 1
if serving is 'A':
if random() < probA:
scoreA += 1
else:
scoreB += 1

  else:
    if random() < probB:
      scoreB += 1
    else:
      scoreA += 1

print(scoreA,'--',scoreB)#print和return的结果代表什么
return Winner(scoreA, scoreB)#
def gameOver(scoreA, scoreB):#这里返回的true和false有什么用
if scoreA == 10 & scoreB == 10:
return False
elif scoreA == 12 or scoreB == 12:
return True
else:
return scoreA == 11 or scoreB == 11
def switchServing(i, serving):
ifi%5==0 and i>0:
if serving is 'A':
serving = 'B

1.print和return的结果代表什么?
print(scoreA,'--',scoreB)表示输出AB两者的分数,return Winner(scoreA, scoreB)表示将两人的分数作为参数传给
Winner函数,当Winner函数得出谁是胜者后将胜者作为simOneGame的返回值返回
2.这里返回的true和false有什么用?
这里的true和false作为标志变量由gameOver函数返回,用于while not gameOver(scoreA, scoreB):这一行判断while循环是否进行
3.#11,12行和33行def switchServing的关系?
这里你贴的码没贴好我也不清楚11,12行在哪

img