[Tutor] Hands-on beginner's project?

Alan Gauld alan.gauld at btinternet.com
Tue Jun 24 22:32:52 CEST 2008


"nathan virgil" <sdragon1984 at gmail.com> wrote

> I'm very new to Python, and (to a slightly lesser extent) 
> programming in
> general. I'd like to get some experience by practicing 
> simple-yet-functional
> programs,

That is not a bad idea but...

> I figure I just need to use a lot of print, if/elif/else, 
> raw_input(), and a
> ton and a half of variables.

That's a terrible idea! :-)

> reading about some language using a "goto" command for something 
> like this,
> but I'm not sure how that would be handled in Python.

It's not. Goto is one of the bad ideas of programming from the
1960s and almost all modern languages do not support it.
It leads to very unstructured programs that rapidly become
unreadable and therefore unmaintainable. Python tries very
hard to stop you writing bad code so it does not have a goto.

> A rough idea of what I'm trying to do (in a presumably hypothetical
> language) would be something like this:
>
> 0100  print "Ahead of you, you see a chasm.
> 0200 jump = raw_input("Do you wish to try jumping over it? Y/N")
> 0300 if jump = Y:
> 0400       goto 1700
> 0500 if jump = N:
> 0600      goto 2100
>
> Is there some way I could do this in Python?

Fortunately not. However there are much better alternatives and
if you take just a few hours to go through any of the non-programmers
guides on the python web site you will find out what they are.
I would recommend Josh Calgierri's(sp?) tutor since it is very
hands-on which seems to be your preferred style but he will
lead you through examples that show you how to structure
your code much more effectively than using gotos.

http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python/Contents

In particular look at the Decisions and Defining Functions topics.

I suspect you would find my tutorial to be too heavily biased
to the theory and foundation stuff. But you can try it if you like,
the Branching and Functions topics apply.

Doing these tutorials may seem a bit slow and dry but they will
save you a lot of time later and prevent you from learning a heap
of bad habits that will make life harder inthe long run. (It will also
save you posting lots of very basic questions here and then
waiting for the replies!)

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list