Confused newbie

Piet van Oostrum piet at cs.uu.nl
Sun Sep 16 15:34:11 CEST 2001


>>>>> "Ron White" <rwhite at netins.net> (RW) writes:

RW> I downloaded Python 2.1.1 (a little over 6 meg) and installed it in a win95
RW> machine.

RW> I am going through Josh Cogliati's Non-Programmers Tutorial for Python and
RW> there are several questions I hope I can get answers to.

RW> First, is there a document which tells you how to indent the various
RW> cammand lines? I have a lot of trouble with that.

The language reference manual will tell you exactly when to indent, but it
may be a bit too complicated for a newbie.
In general all Python constructs consisting of more than one part should
have their bodies indented:

if x<3:
    a = 1
else:
    a = 3

while x<3:
    x = x+2

def func(x):
    print x+2

etc.

It is not important how much you indent if only the statements that belong
together (at the same level) have the same indentation:

if x<3:
    a = 1
    b = 2

Not:
    a = 1
   b = 3
neither:
    a = 1
     b = 3

Of course nested constructs have their own indentation:

if x < 3:
    a = 1
    while a < 10:
          print a:
          a = a+1
    b = 2

Note that a, while and b have exactly the same indentation.

I hope you get it.
One warning: it is stronly discouraged to mix TABs and spaces.

RW> Secondly, I have typed in a program for printing out a calendar, but
RW> when I try to run it I get the error that this program has committed a
RW> fatal error and will be shut down.

How did you start it?

RW> I thought maybe I didn't have the calendar library, but it appears that
RW> I do in lib. One thing I've wondered is if I should have installed
RW> Python on drive c instead of drive e - maybe the program can't find the
RW> lib directory? The program is:

If you used the normal installer it should be Ok on E: I think.

RW> import calendar
RW> year = input("Type in the year number:")
RW> calendar.prcal(year)

The program works for me on Windows 95.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl



More information about the Python-list mailing list