FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
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

It may help you. Wink
Algos
Thanks. But this script outputs only integer numbers. I want to get numbers with floating point.
dimedrol-tab
O_o
Oh sorry Wink It is my error )))
Try to use
Code:
print float(num)/10
instead of
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 Wink)
People, if you have any questions about lists, cycles and function range(), you can ask them in this topic Laughing Laughing Laughing
Related topics
Fortran Tutorials(77)
PlayStation 3
java longer than long?
Programming in Assembly Language: x86 - reserved pixel?
What Runs The Xbox 360 And The PS3 ..... Which Is Better ?
[Visual Basic] Divide X equation
Adobe Photoshop CS2 vs CS3
what is 0 divided by 0?
SQL datatype
Big AWK failures
CPU GHz
sin cos tan
Windows 32 bit or 64 bit
Javascript: double decimal numbers with
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.