You are invited to Log in or Register a free Frihost Account!

# [Python] Numbers with floating point in range

Algos
How can i use numbers with floating point in range() function? Help, please! It is very necessary for me. T_T Thanks in advance...
dimedrol-tab
Uuuum... I think that it is not supported in python. Both parameters of function range() are int...
But there is another way. Try it:
 Code: f0 = float(1.3) f1 = float(4.7) for num in range(f0*10,f1*10):     print num/10

Algos
Thanks. But this script outputs only integer numbers. I want to get numbers with floating point.
dimedrol-tab
O_o
Oh sorry It is my error )))
Try to use
 Code: print float(num)/10
 Code: print num/10
Algos
Oh, it works. Thanks a lot!
Algos
I have one more question.
I type this code:
 Code: l = [14, 4, 567, 12, 7, 8, 88] for num in range(0,len(l)):    rl = list()    if len(rl) == 0:       rl = l[num]    else:       if l[num] < rl[0]:          rl = [ l[num] ] + rl       elif l[num] > rl[-1]:          rl = rl + [ l[num] ]    l = rl
and see TypeError: 'int' object is unsubscriptable.
Why? How to fix that?
dimedrol-tab
Don't write code, that was writen by python developer ;D
List class has a method sort()
 Code: >>> l = [14, 4, 567, 12, 7, 8, 88] >>> l.sort() >>> l [4, 7, 8, 12, 14, 88, 567]
dimedrol-tab
Huh )
People, if you have any questions about lists, cycles and function range(), you can ask them in this topic