[Tutor] Baffled: why doesn't range work?

alan.gauld@bt.com alan.gauld@bt.com
Fri, 27 Jul 2001 11:04:17 +0100


> class mtrx:
>     def __init__(self, numRows = 1, numCols = 1, initVal=0):
>         self.numRows = numRows
>         self.numCols = numCols
>         self.data = {}
>         if initVal != 0:
>             for i in range(1, numRows + 1, 1):
>                 for j in range(1, numCols + 1, 1):
>                     self.data[(i, j)] = initVal
> 
I tried your code and got:
>>> m = mtrx(2,5,0.2)
>>> m.data
{(2, 3): 0.20000000000000001, (2, 2): 0.20000000000000001, 
 (1, 4): 0.20000000000000001, (1, 5): 0.20000000000000001, 
 (1, 2): 0.20000000000000001, (1, 3): 0.20000000000000001, 
 (2, 4): 0.20000000000000001, (1, 1): 0.20000000000000001, 
 (2, 1): 0.20000000000000001, (2, 5): 0.20000000000000001}
>>>

ie. It looks fine...

Alan G