比赛nsn
作者:互联网
import random as a
def getput():
jia = eval(input('甲的胜率:'))
yi = eval(input('乙的胜率:'))
n = eval(input('比赛场次:'))
return jia,yi,n
def bishaileixing():
c=input('比赛类型:')
if c =='单打淘汰赛':
return 7
elif c=='双打淘汰赛' or '团体赛':
return 5
def danda(x,y):
if x==4:
return '本场比赛甲胜利'
elif y==4:
return '本场比赛乙胜利'
def shuangda(x,y):
if x==3:
return '本场比赛甲胜利'
elif y==3:
return '本场比赛乙胜利'
def yichangbishai(c): #传入比赛类型
x,y=0,0
gameover(x,y)
for i in range(bishaileixing()):
yijubishai(a,b)
if c =='单打淘汰赛':
danda(x,y)
elif c=='双打淘汰赛' or '团体赛':
return 5
if scoreA>scoreB:
x+=1
else:
y+=1
return winsA,winsB
def yijubishai(a,b) #传入能力值
'''模拟一局比赛的场景'''
x=0
y=0
#本局比赛谁先发球(设定每局比赛总是球员A先发球)
starting='A'
while not gameover(x,y):
if starting=='A':
#random()函数用来生成一个随机小数,范围在区间 [0,1)内
if a.random()<a:
x+=1
else:
starting='B'
else:
if a.random()<b:
y+=1
else:
starting='A'
if gameover(x,y) ==a:
return x1+=1 #本局比赛A赢,赢的场数加一
elif gameover(x,y)==b:
return y1+=1 #本局比赛B赢,赢的场数加一
def gameover(a,b):
if a==10 and b ==10:
if a-b==2:
return a
elif b-a==2:
y+=1
return b
elif a ==11 and b != 10:
x+=1
return a
elif b==11 and a!=10:
y+=1
return b
def main():
A,B,N=getput()
bishaileixing() #比赛类型
yijubishai(A,B)
yichanbishai(bi
bishaileixing(c)
学号:2020310143011
标签:elif,return,比赛,nsn,random,淘汰赛,def 来源: https://www.cnblogs.com/jiujiuwawa/p/15677983.html