Happy birthday in python

2 comments

In a fit of genius while I was surfing the net, I came up with a python implementation of the song "Happy Birthday". It's totally sweet!

you = Person()

for i in range(0, 4):
    if i == 2:
        you.name = happy_birthday
    else:
        you = happy_birthday

Sometimes my genius is a little subtle, so here's how it works:
- 'you' is an instance of a 'Person' object.
- The 'you = happy_birthday' is assigning "happy_birthday to you".
- The third time through 'happy_birthday' is assigned to the person objects 'name'. So if the person objects name was 'Scott', this would be assigning "happy_birthday to Scott".

And just for fun, I wrote a one liner that will print out the happy birthday song, using python:

for i in range(0, 4): print "Happy Birthday", ((i == 2 and ("Dear Scott",)) or ("to you",))[0]

Peanut Gallery

you are such a geek.

midge

you are such a geek.

Damn, you need a g/f!!

ts

Damn, you need a g/f!!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options