dimanche 22 octobre 2017

Python 3.5: Syntax Error for Else Statement inside function

I have tried debugging multiple times but can't figure out why I'm getting invalid syntax for the else statement.. I'm pretty sure I've defined all my variables and have the correct parentheses.

from math import factorial as ǃ

import numpy as np

FD = list(numpy.random.binomial(1,0.3,4096)) 
n =  len(FD)
H = np.arange(0.001,1.,0.001)

def ლ(N,r,H):
    if N >= 10: #Stirling Approximation for N > 10
        ლ = np.exp(N*np.log(N/(N-r)) - (r*np.log(r/(N-r)))- np.log(2*np.pi) + 0.5*(np.log(N/(r*(N-r)))+ (r*np.log(H)) + ((N-r)*np.log(1-H))
    else:       #Stirling's Approximation not necessary for N < 10
        ლ = (((ǃ(N))/(ǃ(r)*ǃ(N-r))))*H**r*(1-H)**(N-r))
    return ლ

Please note the exclamation mark is a genuine character I copied and pasted. It's not the same as the one you find on the keyboard.

If anyone can spot any problems with my code, please let me know.

Aucun commentaire:

Enregistrer un commentaire