## Python Code for Tennis Markov

I’ve published my code for the tennis markov project. You can find it here:

- Single game outcome. Takes the server’s probability of winning a single point and the current score, returns server’s chance of winning game.
- Tiebreak outcome. Takes server’s probability of winning a single service point, prob of winning single return point, and current score, returns server’s chance of winning tiebreak.
- Single set outcome. Takes server’s probability of winning a single service point, prob of winning single return point, and current game score, returns server’s chance of winning set. (Assumes standard tiebreak set.)
- Match outcome. Takes server’s probability of winning a single service point, prob of winning single return point, current score in points, games, and sets, and number of sets, returns server’s chance of winning match.

The logic in the tiebreak problem is knotty, and the code reflects that; I’m sure there’s a better way of doing it, I just didn’t feel like working it out once I got to the answer.

In the other functions, the code is pretty clean, and I’ve commented it more than I otherwise would. The math gets a little hairy, though.

David Pintosaid, on January 13, 2011 at 5:42 pmI’m glad to see someone else doing sports research in Python!

Mr. Redsaid, on January 14, 2011 at 3:29 amI’ve started messing around with Python after your recommendation in “Python for baseball.” However, I can’t seem to find a free Python IDE that I really like. What do you use?

Thanks,

Mr. Red

Jeffsaid, on January 14, 2011 at 3:20 pmI use IDLE, which is part of the standard python download. I’m easy to please, though.