Programming Tutorial for absolute beginners

Duncan Smith buzzard at urubu.freeserve.co.uk
Sat Apr 8 22:25:38 EDT 2006


Clodoaldo Pinto wrote:
> Duncan Smith wrote:
> 
>>James wrote:
>>
>>>Perhaps use the phrase "whole number" there and mention that in
>>>programming they're called integers. Having a glossary with
>>>definitions for things like integer, float etc etc. would be good if
>>>when you talked about integers it linked to the glossary. And
>>>similarly use "decimals" for floats? Less sure about that one though.
>>>But anyway you don't need to go into the whole type thing, just
>>>mention that Python distinguishes between doing maths with whole
>>>numbers and decimals.
>>>
>>
>>In general they are integers, and "integer" is not a Python type, so I
>>don't see a problem with the term.  The problem I saw was that there was
>>no explanation for the returned value.
> 
> 
> How would I explain that 3 / 2 is 1 without entering the type realm?

Well you said something like "it returns an integer" without explaining
why the returned integer was 1 rather than, say, 10.  So you probably
need to explain what integer division is, e.g.
http://mathworld.wolfram.com/IntegerDivision.html.

> What if I say that if one don't use the point the interpreter will also
> not use it? Would i be laying? Isn't it better to just let it go?

I reckon letting it go would lead to confusion.  If I didn't know
already, I'd want to know why it returned 1.  You can explain that
without referring to types, but just saying e.g. that ordinary division
is performed if the numerator or denominator is followed by a decimal point.

But as you use conversions to float in order to avoid integer division
in your code examples, it might be best to explain what's going on, even
if you do have to explain the relevant types.

I
> think the typical non programmer newbie just don't care two much about
> reasons as long as there is a clear rule. No point in the question then
> no point in the answer.
> 

I can't imagine anyone (who doesn't already know) looking at the example
and not wondering why it returned 1 rather than something else.

> 
>> Using the term "decimal" is
>>probably a bad idea, given Python decimals.  But I'm not sure you need
>>to come up with a suitable term until you actually get round to
>>explaining types (at which point the problem disappears).
>>
> 
> 
> As I think float is scaring I changed it in the program comments where
> it appeared for decimal. I don't worry about precision as much as I
> worry about fluidity. I don't want anyone stoping to consult a
> dictionary or a glossary.
> 
> Now the integer versus whole. As a non native english speaker I don't
> know what sounds less mathematical and more natural. I changed integer
> to whole following the previous suggestion but I really don't know.
> 

Integer is more mathematical, and more precise.  I just looked up some
definitions for "whole number", and found it can apparently mean
positive integer, non-negative integer, or integer.  Maybe you can use
integer and just put "whole number" in brackets after it, the first time
you use it; as a vague definition?  But describing the relevant types
and integer division might make your later examples clearer.

Duncan



More information about the Python-list mailing list