You will need to use ==
, not is
, for equality comparisons:
if team2 == "Bye":
is
is for identity comparison, which you need very, very rarely.
As an aside, you can do this without Numpy (though I might have the <
operator the wrong way around here :-) ) since the probabilities would sum up to 1, and random.random()
returns a random value between 0 and 1:
import random
def simulate_game(team1, rating1, team2, rating2):
if team2 == "Bye":
return team1
pteam1 = 1 / (1 + 10 ** ((rating2 - rating1) / 250))
return team1 if random.random() < pteam1 else team2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…