472,980 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,980 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 1118
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

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

Similar topics

30
by: Alf P. Steinbach | last post by:
The C++ FAQ item 29.5 (this seems to be strongly related to C), at <url: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5> mentions that <quote> C++ guarantees a char is exactly one...
2
by: Ben O'Steen | last post by:
Scenario: ========= Using PyGame in particular, I am trying to write an application that will run a scripted timeline of events, eg at 5.5 seconds, play xxx.mp3 and put the image of a ball on...
2
by: Loribeth | last post by:
Hi All, I am working on a sub that will loop through a recordset and validate that the ranges are valid, ie no overlapping values - no gaps in the ranges. I am pretty sure I have the validation...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
5
by: John Brock | last post by:
I am using VB.NET to read Excel workbooks which have various named ranges, some of which may not exist in any given workbook. I am trying to get a list of all the range names -- otherwise I need...
6
by: Robin Haswell | last post by:
Hey guys I was wondering if you could give me a hand with something. If I have two tuples that define a range, eg: (10, 20), (15, 30), I need to determine whether the ranges overlap each other....
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
9
by: Christoph Bartoschek | last post by:
Hi, some time ago I've read a paper that advised to store intervals on discrete values in the format [a;b[. One starts with the first element and finishes with one past the last one. However...
3
by: Snedker | last post by:
Hi there, I really need some input of how to approach my little assignment. A customer wants to exclude all US IP-ranges from accessing part of his website. From...
7
by: guido | last post by:
Hi, I'm looking for a container class that can map whole ranges of keys to objects - something like std::map, but not only for individual values for the key, but for whole ranges. Example: I...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.