[Tutor] help

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Mon, 14 Aug 2000 00:58:17 -0700 (PDT)


On Sat, 12 Aug 2000, Richard E. Doksa wrote:

> i got a sample program from python.org on makeing a calculator and i
> cant make python except some of the code. i dont know when to push
> enter and when not to.sometimes i enter the code just like the example
> and i still get errors? i am just starting out with python please send

The very beginning is usually a little difficult; don't worry too much
about it.  Python depends a lot on indentation, so you might get errors
because of indentation errors.  There are also a bunch of small things
that you'll get used to, once you see them.

It makes things much easier if you work with a nice text editor, such as
IDLE or Emacs, because those editors handle indentation almost
automatically for you.

Anyway, I'll try to guess at your problems, and show why they're buggy.  
Here's a pretty tediously silly interpreter session with explanations
headed by '###':


### I want to learn how to use the 'if' statement.
###
>>> name = raw_input("Please enter your name")
Please enter your nameDanny

### Hmm, that looked weird, but that's just because I forgot to put a
### color or space in my raw_input call.
###
###     raw_input("Enter name: ")
###
### would look ok.

>>> if name == danny
  File "<stdin>", line 1
    if name == danny
                   ^
SyntaxError: invalid syntax

### This happened because it looks like I'm trying to use a 'danny' 
### variable, but it hasn't been created yet.  I really meant to compare 
### against the _string_ "danny".  I must remember to quote strings.

>>> if name == "danny"
  File "<stdin>", line 1
    if name == "danny"
                     ^
SyntaxError: invalid syntax

### Whoops.  Forgot the colon --- 'if' statements need to show that you're
### starting the 'if' block by using a colon.

>>> if name == "danny":
... print "Hello to myself"
  File "<stdin>", line 2
    print "Hello to myself"
        ^
SyntaxError: invalid syntax

### That was silly --- I forgot to indent my print statement; this is
### because the 'if' needs to take in a block of instructions, even if
### there's just one statement in the block.  However, I could have just
### done:
###
###     if name == "danny": print "Hello to myself"
###
### on one line, and it would have worked too.  (This only works for
### one-liners.)

>>> if name == "danny":
...     print "Hello to myself"
... 
>>>            

### Hey, nothing happened.  Oh, that's because 'Danny' is capitalized
### and 'danny' isn't.  Grrr.

>>> if name == "Danny":
...     print "Hello to myself"
... 
Hello to myself
>>>

### Ah, finally!

I hope this highlighed some of the problems you were getting, but of
course I can only guess.  If you can show us the error messages that
you're getting, we can help explain them.


> me anything you think will help me? also i was told that python is a
> good language to start out on is that true? i have never done any
> programing before and i would like to learn as many languages as
> possible where should i start?

One thing at a time!  *grin* It's good that you're trying to learn as
quickly as you can.  Yes, Python's a good language to start with.  If
someone hasn't directed you to a Python tutorial yet, take a look at
these:

Josh Cogliati's Non-Programmer's Tutorial for Python:

  http://www.honors.montana.edu/~jjc/easytut/easytut/

Alan Gauld's Learning to Program:

  http://members.xoom.com/alan_gauld/tutor/tutindex.htm


Once you're gotten fluent with Python, you might want to look at something
entirely different, like Scheme.  Scheme's another programming language
from the Lisp family.  Most likely, it will take you completely by
surprise when you see it.  Here's a link to one of their sites:

  http://www.cs.rice.edu/CS/PLT/Teaching/


You can pretty much branch off anywhere your interest leads you to.  Try
to apply what you've learned, so that you can better understand the
techniques.  Anyway, sorry for the length of this message; I babble a lot.  
Good luck!