471,321 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

ranges

how do you make a program with ranges? for example if i wanted to make a program classifying dogs, where the user enters variables, maybe height and weight for example, and i had where,
between 42 - 65 cm is bulldog
30 - 40 cm is terrier
50 - 67 cm is labrador
and between 24.3 - 46.7 kg is bulldog
4.5 - 11.5 kg is terrier
27 - 34kg is labrador

how can i search within a range, and should i set up the data in a dictionary, or list?
Oct 14 '07 #1
1 1065
bartonc
6,596 Expert 4TB
how do you make a program with ranges? for example if i wanted to make a program classifying dogs, where the user enters variables, maybe height and weight for example, and i had where,
between 42 - 65 cm is bulldog
30 - 40 cm is terrier
50 - 67 cm is labrador
and between 24.3 - 46.7 kg is bulldog
4.5 - 11.5 kg is terrier
27 - 34kg is labrador

how can i search within a range, and should i set up the data in a dictionary, or list?
Here's one way:
Expand|Select|Wrap|Line Numbers
  1. >>> 3 < 5 < 7 # is 5 between 3 and seven?
  2. True
  3. >>> 5 < 3 < 7 # is 3 between 5 and 7?
  4. False
  5. >>> 
  6. >>> dd = {'bulldog':(42, 65), 'terrier':(30, 40)}
  7. >>> size = 35
  8. >>> for key, value in dd.items():
  9. ...     if value[0] < size < value[1]:
  10. ...         print key
  11. ...         
  12. terrier
  13. >>> 
Oct 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

30 posts views Thread by Alf P. Steinbach | last post: by
12 posts views Thread by Steve Elliott | last post: by
5 posts views Thread by John Brock | last post: by
6 posts views Thread by Robin Haswell | last post: by
67 posts views Thread by PC Datasheet | last post: by
9 posts views Thread by Christoph Bartoschek | last post: by
3 posts views Thread by Snedker | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.