Webucator's Blog

|

Markdown ATX Headers Require a Space after Hashes

I just upgraded to Anaconda 2.4, which includes Python 3.5. To update, just run the following code:

conda update conda
conda install anaconda=2.4 

Almost everything seems to have gone smoothly. The exception was that all the markdown headers in my IPython notebooks lost their formatting. They started showing up like this:
Broken Markdown Headers Continue Reading »

|

Python Coding Challenge: Two People with the Same Birthday

Python Coding Challenge: You’re in New York City. You walk up to a stranger and ask her what her birthday is. If her birthday is the same as yours, you win. If not, you take her hand and the two of you walk up to another stranger and ask him his birthday. If his birthday is the same as either of yours, you win. If not, one of you takes his hand, and you walk up to another stranger… Keep going until you find someone who has the same birthday as someone else in your group. Use Python to figure out how many tries it will take you. Continue Reading »

|

Statistics are Funny

Mark Twain wrote “There are three kinds of lies: lies, damned lies, and statistics.” And statistics indeed can be misleading (intentionally or otherwise).

In baseball, batters who can hit from either side are called switch hitters. They generally hit from the right side against left-handed pitchers and from the left side against right-handed pitchers. Let’s say that you’re a baseball manager and that you need to add a switch hitter to your team. You are considering two different players. Each of the players has had 5,000 major league at bats. Player 1 has a batting average of .296 and Player 2 has a batting average of .315. Let’s say they hit the same number of extra base hits, steal the same number of bases and are equally good fielders. It seems obvious that you should choose Player 2 as he has a significantly higher batting average. Continue Reading »

|

How to Create a Simple Simulation in Python – Numeric Data

In this post, I show how to create a simple Simulation class in Python. The purpose of the class is to run a simulation many times and then return stats (e.g., mean, median, etc.) on the results of the simulation.

Let’s start with a simple Die class that has a roll() method that returns an integer between 1 and 6 (inclusive): Continue Reading »