Geronimo89.dk

A blog about me, my doings and everything I think deserves attention.

flexible dice

dice 300x289 flexible dice

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# author: Jonathan M. Hethey
# website: http://geronimo89.dk
# A flexible dice that can help you making decisions
import random	# it's necessary to import this function to choose a random number from a range later
print("Please insert your choices, press enter and make the dices roll with \"end\"")	# This gives the user an idea how this works</div>
Options = []		# introducing the array/list
while "end" not in Options:		# as long as "end" is not an entry in "Options
Options.append(raw_input(""))		# the keyboard entries are being added to Options
Options.remove("end")		# removing "end" from the list
randomsum = len(Options)		# reading the length of the list, defining the randrange
randomnumber = random.randrange(randomsum)		# the random function
print "The dice tells you: ", Options[randomnumber]		# Here the right entry is read from the list

Finally, it’s done. I’ve played with the idea of a flexible dice for quite a time, but I’ve finally managed to code it (now that I’m finished I see that it really is no big deal). My goal with this program was a dice with sides the user could define and it should be able to have as many options as wanted. Documented version in German and English is attached to this post. If you want to run this within Linux you probably need the python or python2.5 package provided by the team of your distribution. If you want to use it with Windows, maybe my little guide to cygwin could help you.

Give me the first comment

Leave a Reply