2008, June 8

flexible dice

Filed under: code — Tags: , — jonathan.hethey @ 01:25

# A flexible dice that can help you making decisions
import random
print("Please insert your choices, press enter and make the dices roll with \"end\"")
Options = []
while "end" not in Options:
Options.append(raw_input(""))
Options.remove("end")
zufallssumme = len(Options)
zufallszahl = random.randrange(zufallssumme)
print "The dice tells you: ", Options[zufallszahl]

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.

Download:

0x_flexible_dice1 English version

0x_flexiblerwuerfel1 German version

2006, September 16

coding

Filed under: code — Tags: , , — jonathan.hethey @ 13:27

Since I always was focussed on design I decided that my lousy skills needed some work on them. I started nosing around about the topic and found things I could use. The site freetechbooks.com offers a lot of free documents containing computer science and programming. The ebook I am reading right now is written as an introduction to programming with python. It’s called think like a computer scientist. After only 3 chapters I can tell it really helps understanding essentials. Moni and me are doing the php-q tutorial together and having some fun with that too. While writing this entry I found another easy and fun to learn language, it’s called ruby and you can try it online here. Python and Ruby are, as far as I could experience, following the KISS principe (keep it simple stupid).

Let’s have a short look at methods in ruby:

geronimo@Zero-1:~$ irb1.8
irb(main):001:0> def greetings(name)
irb(main):002:1> puts "Rise and shine #{name}..."
irb(main):003:1> end
=> nil
irb(main):004:0> greetings("sleepyhead")
Rise and shine sleepyhead...
=> nil