Rolling Dice With Python


A buddy of mine asked me a couple days ago if it’d be possible to write a program that rolled dice and dealt with the results in a certain way. Seeing this as an opportunity to dabble in some programming I naturally replied that 1) Yes, it’s possible, and 2) I’ll do it for you.

The obvious choice for the job was Python.

Anyway, the task took an embarassingly long time (over 3 hours), but I didn’t feel bad about it considering my limited programming experience. Plus, the old saying about only getting good at programming by doing it is quite true.

At any rate, here’s what I came up with for the basic task, which was to roll 2-9 d6 and add the two highest rolls. From here I’m going to add the ability to provide a second argument that determines how many times the roll with x number of dice will be made. That version will also keep a running average of the totals from each roll.

Related posts: