Programming Tutorial for absolute beginners

Frank Millman frank at chagford.com
Sun Apr 9 04:49:45 EDT 2006


Clodoaldo Pinto wrote:
> James wrote:
> > On the calculator page you describe the difference between 3.0 / 2 and
> > 3 / 2, but an absolute beginner probably wouldn't know about the
> > difference between integers and floats, or even what the two terms
> > meant. If you don't know much about computers then the fact that they
> > are separate types would probably be surprising...
> >
> This point is not easy to aproach. The fact is that it is necessary
> that the beginner knows that there is a differerence between 3 / 2 and
> 3.0 / 2.
>
> I don't want him to now about types, at least not at that stage. I used
> the term "integer" for the lack of a better one and I didn't mention
> "float". Any suggestions?
>
> Regards, Clodoaldo.

Here is a idea. I am not sure if it is a good idea, but you can compare
it with the other suggestions for resolving this dilemma.

We know that Python is in the process of changing the division
operator. The main reason for the change is that the current approach
is not intuitive to a newcomer (whether experienced or not).

Why not think to the future, and do it like this. Instruct the reader
to enter 'from __future__ import division'. You do not have to explain
the details, just say that this is the way division will work in the
future, and this statement will eventually not be required.

Then your example will show that 3/2 = 1.5, which is what they would
expect.

Then you can mention that, if they just want the integer portion, they
can use int(3/2). I think that most people with the slightest
understanding of basic arithmetic will relate to this without a
problem.

My 2c

Frank Millman




More information about the Python-list mailing list