0

I'm trying to figure out how to use upper and lower limits from statistics in my code. I wasn't able to find a function in the statistics module that would help me do this. I want to input a number and check to see whether it will fall within the range of 6.5 to 7.6. I wanted to be able to check this input from (6.5, 6.6, 6.7......7.6) and this code doesn't seem to be working. Any help would be appreciated. Thanks

import numpy as np

interval = float(input("Enter any number: "))

if interval is np.arange(6.5, 7.6, .1):
    print("In Range")
else:
    print("Number out of range")
podjv
  • 3
  • 2
  • Does this answer your question? [How to use a decimal range() step value?](https://stackoverflow.com/questions/477486/how-to-use-a-decimal-range-step-value) – deadvoid Jan 20 '20 at 17:13
  • (1) Should be if interval in range, not if interval is range. 'in' checks membership while 'is' checks object equality between references. (2) float values have limited precision and therefore will not be 'exact' values, such as with integers. You can make a list that rounds each value [round(x,2) for x in np.arange(6.5, 7.6, .1)], or use a decimal range() step value. – spacecowboy Jan 20 '20 at 17:38
  • I'm still new to Programming. That was helpful Thank You – podjv Jan 20 '20 at 18:40
  • The duplicate about decimal `range` doesn't help. `arange` already handles a float step. The issue here is how to test against that array, not how to generate it. – hpaulj Jan 20 '20 at 19:10
  • It should be reopened. I didn't review my question appropriately – podjv Jan 20 '20 at 19:37
  • If the input is 6.55, should the result be `True` ("in range") or `False` ("out of range")? – mkrieger1 Jan 21 '20 at 02:00
  • What about `if 6.5 <= interval <= 7.6:` – schwartz721 Jan 21 '20 at 05:30

0 Answers0