[Tutor] Range of float value

2007-02-08 Thread Johan Geldenhuys
Hi all,
 
I have a value that ranges between 48.01 and 48.57. a Float value in other
words.
 
I want to look at changes in the value. If my normal range is between 48.35
and 48.45, how will I identify the value below 48.35 and above 48.45?
 
Something I tried was:
 
for a in range(48.35, 48.45):
print a
 
It gives me a value of 100.
 
Is it possible to get a range of a float value?
 
Thanks
 
Johan

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.30/674 - Release Date: 2007/02/07
03:33 PM
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Luke Paireepinart
Kent Johnson wrote:
 Johan Geldenhuys wrote:
   
 Hi all,
  
 I have a value that ranges between 48.01 and 48.57. a Float value in 
 other words.
  
 I want to look at changes in the value. If my normal range is between 
 48.35 and 48.45, how will I identify the value below 48.35 and above 48.45?
  
 Something I tried was:
  
 for a in range(48.35, 48.45):
 print a
  
 It gives me a value of 100.
  
 Is it possible to get a range of a float value?
 

 You can't generate all the float values in a range. (OK, you probably 
 could, but it would not be practical or useful.) You can test for a 
 value in a range, e.g.
 if 48.35 = a = 48.45:
   
Kent:
Why does this work?
In C++ this would go from

if (48.35 = a = 48.45)

to (assuming the right condition is met)

if (48.35 = true)

because it evaluates these things right to left, doesn't it?
does python treat chained comparisons differently than C++ or is C++ 
behaving differently than I think it does?
Thanks for your help,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Kent Johnson
Luke Paireepinart wrote:
 Kent Johnson wrote:

 You can't generate all the float values in a range. (OK, you probably 
 could, but it would not be practical or useful.) You can test for a 
 value in a range, e.g.
 if 48.35 = a = 48.45:
   
 Kent:
 Why does this work?

It is explicitly supported in Python. See
file:///C:/Python25/Doc/ref/comparisons.html

which says, Comparisons can be chained arbitrarily, e.g., x  y = z is 
equivalent to x  y and y = z, except that y is evaluated only once 
(but in both cases z is not evaluated at all when x  y is found to be 
false).

Kent

 In C++ this would go from
 
 if (48.35 = a = 48.45)
 
 to (assuming the right condition is met)
 
 if (48.35 = true)
 
 because it evaluates these things right to left, doesn't it?
 does python treat chained comparisons differently than C++ or is C++ 
 behaving differently than I think it does?
 Thanks for your help,
 -Luke
 
 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Andre Engels

2007/2/8, Johan Geldenhuys [EMAIL PROTECTED]:


 Hi all,

I have a value that ranges between 48.01 and 48.57. a Float value in other
words.

I want to look at changes in the value. If my normal range is between
48.35 and 48.45, how will I identify the value below 48.35 and above 48.45
?

Something I tried was:

for a in range(48.35, 48.45):
print a

It gives me a value of 100.

Is it possible to get a range of a float value?



It depends. What would you like it to be? All numbers in that range? They're
uncountably infinite, so no way we could ever get that out of the computer.
All actual float values? Depends too much on the implementation of the
specific machine you're working on to be workable.

Identifying values below 48.35 and above 48.45 is simply done by:
if value  48.35 or value  48.45 then...

No need to first create the range of values

--
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Luke Paireepinart
Kent Johnson wrote:
 Luke Paireepinart wrote:
 Kent Johnson wrote:

 You can't generate all the float values in a range. (OK, you 
 probably could, but it would not be practical or useful.) You can 
 test for a value in a range, e.g.
 if 48.35 = a = 48.45:
   
 Kent:
 Why does this work?

 It is explicitly supported in Python. See
 file:///C:/Python25/Doc/ref/comparisons.html
Do you mean http://docs.python.org/ref/comparisons.html ?
:)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Kent Johnson
Luke Paireepinart wrote:
 Kent Johnson wrote:
 Luke Paireepinart wrote:
 Kent Johnson wrote:
 You can't generate all the float values in a range. (OK, you 
 probably could, but it would not be practical or useful.) You can 
 test for a value in a range, e.g.
 if 48.35 = a = 48.45:
   
 Kent:
 Why does this work?
 It is explicitly supported in Python. See
 file:///C:/Python25/Doc/ref/comparisons.html
 Do you mean http://docs.python.org/ref/comparisons.html ?

Jeez. I try so hard to bust out of here and every turn I take just 
brings me back to file://.

Now where did I put that internet, anyway?

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Johan Geldenhuys
OK, this what I wanted:
 
I have a value: a = 48.41
 
My lowValue is: lowValue = 48.35
My highValue is : highvalue = 48.45
 
if a = lowValue:
print 'value below limit'
 
if a = highValue:
print value above limit'
 
I though that it could be possible to have a range between 48.35 and 48.45
that could have a step of 0.1
 
This works fine with normal intgers:
 
 def lookAtRange(a):
... if a in range(40, 110, 10):#Would like to have: if a in
range(48.35, 48.45, 0.1):
... print 'In limits'
... else:
... print 'Out of limits'
... 
 lookAtRange(40)
In limits
 lookAtRange(50)
In limits
 
 lookAtRange(20)
Out of limits
 
 lookAtRange(120)
Out of limits
 
 
Johan
 

   _  

From: Andre Engels [mailto:[EMAIL PROTECTED] 
Sent: 08 February 2007 07:17 PM
To: [EMAIL PROTECTED]
Cc: tutor@python.org
Subject: Re: [Tutor] Range of float value


2007/2/8, Johan Geldenhuys HYPERLINK
mailto:[EMAIL PROTECTED][EMAIL PROTECTED]: 

Hi all,
 
I have a value that ranges between 48.01 and 48.57. a Float value in other
words.
 
I want to look at changes in the value. If my normal range is between 48.35
and 48.45, how will I identify the value below 48.35 and above 48.45?
 
Something I tried was:
 
for a in range(48.35, 48.45):
print a
 
It gives me a value of 100.
 
Is it possible to get a range of a float value?


It depends. What would you like it to be? All numbers in that range? They're
uncountably infinite, so no way we could ever get that out of the computer.
All actual float values? Depends too much on the implementation of the
specific machine you're working on to be workable. 

Identifying values below 48.35 and above 48.45 is simply done by:
if value  48.35 or value  48.45 then...

No need to first create the range of values

-- 
Andre Engels, HYPERLINK mailto:[EMAIL PROTECTED][EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels 


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.30/674 - Release Date: 2007/02/07
03:33 PM



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.30/674 - Release Date: 2007/02/07
03:33 PM
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Kent Johnson
Johan Geldenhuys wrote:
 OK, this what I wanted:
  
 I have a value: a = 48.41
  
 My lowValue is: lowValue = 48.35
 My highValue is : highvalue = 48.45
  
 if a = lowValue:
 print 'value below limit'
  
 if a = highValue:
 print value above limit'
  
 I though that it could be possible to have a range between 48.35 and 
 48.45 that could have a step of 0.1

What is wrong with
def lookAtRange(a):
   if lowValue = a = highValue:
 print 'In limits'
..etc
??

  
 This works fine with normal intgers:
  
 * def lookAtRange(a):
 ... if a in range(40, 110, 10):*#Would like to have: if a in 
 range(48.35, 48.45, 0.1):
 *... print 'In limits'
 ... else:
 ... print 'Out of limits'
 ...
  lookAtRange(40)
 In limits
  lookAtRange(50)
 In limits
 
  lookAtRange(20)
 Out of limits
 
  lookAtRange(120)
 Out of limits
  *

Are you sure this is what you want? Have you tried lookAtRange(45) for 
example?

The range function creates a list of integers:
In [1]: range(40, 110, 10)
Out[1]: [40, 50, 60, 70, 80, 90, 100]

The 'in' operator tests for membership. 40 is in the list; 20 and 45 are 
not.

I think even in the case of integers the range test with  is what you want.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Range of float value

2007-02-08 Thread Daniel Yoo


On Thu, 8 Feb 2007, Johan Geldenhuys wrote:

 OK, this what I wanted:

 I have a value: a = 48.41

 My lowValue is: lowValue = 48.35
 My highValue is : highvalue = 48.45

Range does not work on floats: it's meant to work on integers.



 I though that it could be possible to have a range between 48.35 and 48.45
 that could have a step of 0.1

There's an unsafe assumption here: in general, comparing floats for 
equality won't work unless you are very very careful.  See:

 http://www.python.org/doc/tut/node16.html

Because floats aren't directly comparable (at least under normal cases), 
that negates the idea of build a list of floats and comparing for equality 
against one of them.

However, Kent mentioned a solution that should work better, a chained 
comparison:

 a = b = c

which is true if b is squeezed between a and b.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor