Neko’s world - part 1

Sleeping Neko!

Type the following at the Python prompt:

sleep()

Lazy Neko - look at him sleeping like a baby!

Enough of sleeping - let’s wake him up! Here is what
you have to type:

wakeup()

That’s a good boy (sorry … Neko)! Too much of sleep
is not good, even for cats!

By the way, what are these `sleep’ and `wakeup’? They
are simply commands which put Neko to sleep and wakes
him up.

But then, programmers have this really bad habit of
using big words to describe simple things.

So, a programmer will say that `sleep’ and `wakeup’
are `functions’ - that’s OK for us. What is there in
a name?

Just a small problem - instead of simply typing `sleep’
and `wakeup’, why are we using two brackets in addition?

That will become clear soon …

Neko runs around!

Try the following function at the Python prompt (after making
sure that Neko is awake):

right()

And Neko has moved one position to the right! If you look
at the Python prompt, here is what you will see:

>>> right()
1
>>>

Another small problem - why is the number one getting printed on the
screen? We will find out!

Let’s make Neko move left by typing:

left()

Just as with `right’, `left’ is also printing a one.

Neko is now at the top left corner. Let’s try `left’ once
again … oh no, Neko doesn’t move an inch! How can he -
there is no place to go!

Wait - there is something else. We now see a zero on the
screen! What is happening here?

Guess …

Yes - you are right! Python is printing a zero only if
Neko is not able to move to another cell - otherwise, a
one is printed!

A bit later, we will see how to use this interesting behaviour
of `left’ and `right’ to make Neko do some fun stuff!

Meanwhile, what are you waiting for … try typing `up’ and
`down’ and see what happens!

Neko’s world

Neko’s world looks like a chess board. There are eight horizontal
`rows’ and eight vertical `columns’. We will call the top row
`row zero’ and the last, bottom row as `row seven’. Similarly,
the leftmost column will be called `column zero’ and the
rightmost one, `column 7′.

When Neko is at the top left corner and somebody asks you - “where
is Neko?” - you will just say:

(0, 0)

That is, row 0, column 0.

But - why is the first row called row zero and the first column
called column zero? We usually start counting from one, right?

That’s just for a change - programmers love to do things differently
so that others might think they are smart!

5 Comments

  1. Posted January 20, 2008 at 6:06 am | Permalink

    TODO:

    a) A figure with rows and columns neatly labelled
    b) Maybe, add the row-col markings to the grid itself

  2. Sreeraj
    Posted January 20, 2008 at 3:48 pm | Permalink

    Sir,

    I wonder how much feasible it would be if we can create an “online” interface with neko.
    The way Ajit sir did with phoenix.

    someone with good php experience [or interests] could do it.

  3. Posted January 21, 2008 at 4:39 am | Permalink

    Sreeraj,

    What is the utility of such an interface?

  4. Sreeraj
    Posted January 22, 2008 at 6:53 pm | Permalink

    it may prove useful if the book is to be kept online,
    plus children who do not have a linux distro at home can try it.

  5. Praveen
    Posted January 24, 2008 at 6:12 am | Permalink

    Children who don’t have Linux Distro in home can also play with Neko

    Download Python for windows from http://www.python.org/download/releases/2.5.1/

    add phython to PATH .

    the do as in this book

Post a Comment

Your email is never published nor shared.