[Tutor] range() fractional increment

james carnell jimcarnell at yahoo.com
Tue Mar 31 05:44:28 CEST 2009


1) I feel dumb for asking this.
2) I looked for 20 minutes and didn't find an answer

Trying to make a drawLine function in a 2d array.

example:
x0000   row = 25 : col = 10
x0000   row = 26 : col = 10.3
x0000   row = 27 : col = 10.6
0x000   row = 28 : col = 11
0x000   row = 29 : col = 11.3
0x000   row = 30 : col = 11.6
00x00   row = 31 : col = 12

for row in range(25,31,1):
    for col in range(10,12, 0.3):  #<- Crash Bang doesn't work 0.3 = zero = infinite loop?

so then I tried...

>>> c = 10
>>> while(c < 12.3):
...     print c
...     c += 1.0/3.0
...
10
10.3333333333
10.6666666667
11.0
11.3333333333
11.6666666667
12.0

is there no way to do it with a range function (and have it still look like you're not on crack)?













      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090330/ecf5bf08/attachment-0001.htm>


More information about the Tutor mailing list