[Tutor] Newbie Question. [what is programming good for?]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sun, 4 Aug 2002 20:09:53 -0700 (PDT)


On Sun, 4 Aug 2002, Martin Teves wrote:

> What things can I do whit Python???, I really wanna know.

Hi Martin,

I'll reinterpret your question as "What kind of things can I do with
computer programming?".  It's a similar question, and I hope you don't
mind if I think of it that way.  (I just want to avoid riling up folks who
use different computer languages.  *grin*)



One way we can get a handle on what's possible with programming is to look
at examples.  If you haven't already, you can take a look at the Useless
Python web page:

    http://uselesspython.com

The links there are to programming that people have written, and if you
glance at the descriptions, you'll see all sorts of weird stuff, from
games to cyphers to puzzle solvers to math toys.  Programs are versatile.



A computer is best at performing instructions very quickly, and
programming lets us take control of a computer power.  Programming allows
us to automate whatever we can organize as instructions.


For example, if we were playing a complicated role playing game, perhaps
we might have to role a dice one hundred times to simulate a huge battle.
Now, rolling a dice by hand can be fun, but also be a bit tedious if we
have to do it a lot.


So instead of doing it ourselves, we can get the computer to "roll" for
us.  Here's how we can get the computer to roll the dice one time:

###
>>> print random.randrange(1, 6+1)
4
###


But that's a lot of typing for getting one dice roll.  How is this better
than doing it by hand?


That's where programming comes in: we can tell the computer to do this
several times... or several hundred times!  Here's a small program that
prints one hundred dice roles:

###
>>> for i in range(100):
...     print random.randrange(1, 6+1),
...
6 1 1 2 3 3 3 1 1 2 3 2 1 1 1 6 6 2 5 6 2 6 1 3 3 2 3 2 6 1 1 2 6 6 1 2 1
3 6 2 1 5 6 4 2 4 5 2 4 2 5 5 6 1 4 4 2 4 6 4 4 3 1 6 2 5 6 4 6 5 1 2 6 5
2 2 5 4 6 1 1 6 1 4 1 1 2 1 1 1 6 4 1 5 3 6 4 3 6 6
###


(The text instructions that are on the same lines as the '>>>' and the
'...' are things that I've typed, and the numbers below those lines are
being printed by the computer.)


The instructions themselves aren't so important: what's neat is to see
that, with just two lines of instructions --- "code" --- we have
extraordinary power:  we've just simulated 100 dice rolls!

That being said, programming is good for more than rolling dice.  *grin*
But I hope this example makes some sense: by programming a computer, we
get the power to amplify what we can already do.




For example, people who design games can use programming to share these
games with others without having to cut cardboard or shave plastic pieces:

    http://pygame.org/

Others use programming to help them analyze some large books or data.
Biologists, for example, can use a tool called "BioPython":

    http://biopython.org/

to speed their analysis along.  And still others like doing lots of math
with programming:

    http://www.pfdubois.com/numpy/

All these things could, in theory, be done without programming... or
perhaps not!  It might just be too slow and impractial to do by hand.
That's where programming can come in: it makes hard things possible.



Those three links are Python specific, but we can give you pointers to
other resources if you'd like.  If you tell us more about what you're
interested in, we may be able to show you how programming might fits in.
We often use programming to make something else easier to do.



Best of wishes to you!