[Tutor] extreme basics

Alan Gauld alan.gauld at btinternet.com
Mon Jan 5 19:25:18 CET 2009


"Mr Gerard Kelly" <s4027340 at student.uq.edu.au> wrote

> This is extremely weird, I think.

No, its normal and you got the right reason.... its due to floating 
point
binary representation issues.

> Here is a tiny program:
>
> from math import *
> from Numeric import *

This is probably a bad idea here (in fact its usually a bad idea!) 
since
both math and numeric are likely to have similar names in them
By importing all names from the modules there is a high chance
of name clashes causing strange behaviour.

Better to use

import math, Numeric

Or, if that's too much typing, use

import math as M
import Numeric as N

> x=[0]*10
>
>
> for counter in rangelen((x)):
>      x[counter]=counter*0.1
>
> print x

Although of course you are not using anything from either math or
Numeric in this example, but I assume you intend to!?

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk




More information about the Tutor mailing list