Python,为什么我的脚本没有运行?

Python,为什么我的脚本没有运行?,python,Python,我制作了一个脚本,根据当前得分计算网球比赛中得分的概率 但由于某种原因,当我想运行脚本时,什么都没有发生。解释在脚本上 有什么建议吗 ## calculate the probability of server winning a single game, ## given p(winning single point) and current point score def fact(x): if x in [0, 1]: return 1 r = 1 f

我制作了一个脚本,根据当前得分计算网球比赛中得分的概率

但由于某种原因,当我想运行脚本时,什么都没有发生。解释在脚本上

有什么建议吗

    ## calculate the probability of server winning a single game, 
## given p(winning single point) and current point score

def fact(x):
    if x in [0, 1]:  return 1
    r = 1
    for a in range(1, (x+1)):  r = r*a
    return r

def ch(a, b):
    return fact(a)/(fact(b)*fact(a-b))

def gameOutcome(s, a, b):
    return ch((a+b), a)*(s**a)*((1-s)**b)*s

def gameProb(s=[0.6], v=2, w=1):
    ## function calculates the probability of server winning
    ## a single game, given p(winning any given point) [s],
    ## and the current point score.
    ## v, w = current game score, where love = 0, 15 = 1, etc.
    ## - e.g. 30-15 is v=2, w=1
    ## check if game is already over:
    if v >= 4 and (v-w) >= 2:
        return 1
    elif w >= 4 and (w-v) >= 2:
        return 0
    else:   pass
    ## if deuce or ad score e.g. 5-4, reduce to e.g. 3-2
    while True:
        if (v+w) > 6:
            v -= 1
            w -= 1
        else:   break
    ## specific probabilities:
    if w == 0:  w0 = gameOutcome(s, 3-v, 0)
    else:   w0 = 0
    if w <= 1:  w15 = gameOutcome(s, 3-v, 1-w)
    else:   w15 = 0
    if w <= 2:  w30 = gameOutcome(s, 3-v, 2-w)
    else:   w30 = 0
    if v == 4:
        wAd, lAd = s, 0
        d = 1-s
    elif w == 4:
        wAd, lAd = 0, 1-s
        d = s
    else:
        wAd, lAd = 0, 0
        a = 3 - v
        b = 3 - w
        d = ch((a+b), a)*(s**a)*((1-s)**b)
    if v <= 2:  l30 = gameOutcome((1-s), 3-w, 2-v)
    else:   l30 = 0
    if v <= 1:  l15 = gameOutcome((1-s), 3-w, 1-v)
    else:   l15 = 0
    if v == 0:  l0 = gameOutcome((1-s), 3-w, 0)
    else:   l0 = 0
    ## given d = prob of getting to deuce,
    ## math to divide up further outcomes
    denom = s**2 + (1-s)**2
    wd = (d*(s**2))/denom
    ld = (d*((1-s)**2))/denom
    win = w0 + w15 + w30 + wd + wAd
    lose = l0 + l15 + l30 + ld + lAd
    return win
##计算服务器赢得一场比赛的概率,
##给定p(赢得单点)和当前分数
def事实(x):
如果x在[0,1]中:返回1
r=1
对于范围(1,(x+1))内的a:r=r*a
返回r
def ch(a、b):
申报事实(a)/(事实(b)*事实(a-b))
def游戏结果(s、a、b):
返回ch((a+b),a)*(s**a)*((1-s)**b)*s
def gameProb(s=[0.6],v=2,w=1):
##函数计算服务器获胜的概率
##单个游戏,给定p(赢得任何给定点)[s],
##和当前的分数。
##v,w=当前游戏分数,其中love=0,15=1,以此类推。
##-例如30-15为v=2,w=1
##检查游戏是否已经结束:
如果v>=4且(v-w)>=2:
返回1
如果w>=4和(w-v)>=2:
返回0
其他:通过
##如果平分或平均分为5-4,则减至3-2
尽管如此:
如果(v+w)>6:
v-=1
w-=1
其他:休息
##具体概率:
如果w==0:w0=游戏结果(s,3-v,0)
其他:w0=0

如果w你会在任何地方调用
gameProb
?通常的做法是使用这种模式:

if __name__ == "__main__":
    gameProb()

并将return改为小写。

s
是一个浮点数,因此,替换此行:

def gameProb(s=[0.6], v=2, w=1):

并在脚本末尾调用函数:

print gameProb()
您也可以将其称为:

if __name__ == "__main__":
     print gameProb()

它使您的脚本成为a,这意味着您可以在另一个脚本中导入它,而无需运行行
print gameProb()

Return win
->
Return win
,并查看正在运行的函数,你应该调用适当的函数。因为你没有调用任何东西。你的脚本由一堆函数定义组成。事实上,它什么也没做。看在上帝的份上,读一下PEP-8。如果
在一行中阻止了所有内容,请不要将您放入
。为什么要将
s
列成一个列表?请提前一秒钟:P@PatNowak,我应该把你提到的模式放在哪里?在脚本的末尾。我应该在哪里调用函数?
if __name__ == "__main__":
     print gameProb()