 # Thread: comparing to range of numbers

1. ## comparing to range of numbers

I have a program that randomizes number set A

Now I want to compare if A is equal to any number ranging from x to y.

How do I do that without making a comparison for every number individually?  Reply With Quote

2. What do you mean by number ranging from x to y ? Is it to compare A to values from 5 to 25 for ex. ?
If so, you can add all your values in a list. During a loop you compare A to each values included in your list. Each time you compare, you delete a line in the list, and so on.
The repetition number of your loop has to be the number of your list lines.  Reply With Quote

3. That doesn't seem to solve the problem of me having to write every number in.

What I mean by x to y is to check if A equals any numbers in that range.

So there's no command that works in way of
Code:
`range(x,y)`
or something similar?  Reply With Quote

4. How do I check only range(Alterable value A, 5, 20)?

I can only get it to check if value X = range(Alterable value A, 5, 20).  Reply With Quote

5. Use the variable itself:

Alterable value A = range(Alterable value A, 5, 20)

If Alterable value A = 3
The condition means --> If 3 = 5

If Alterable value A = 15
The condition means --> If 15 = 15

If Alterable value A = 23
The condition means --> If 23 = 20

So the condition is only true when if Alterable value A is in a range from 5 to 20.  Reply With Quote

6. But what I need is "If alterable value A = 1" AND "Alterable value B = (any number between x and y)"

Maybe if I explain what the hell I'm doing in full.

I have two strings that together make a sentence. Depending on the strings the sentence either makes sense, or it doesn't.

The first string has 5 different possibilities, governed by Value A(which goes from 1-5)

Each of those 5 strings has 5 compatible possibilities in string 2. Governed by Value B(which goes from 1-25)

So if A=1 then the compatible strings will be B=1-5
A=2 compatible with B=6-10
etc.

The player will then click on a tick or an X to say if a sentence is correct or not.

So I was looking for a quick way to compare A against a range of numbers in B.

I ended up using >= and <= five times instead. Which works, I was just hoping there'd be an even easier way to do it.  Reply With Quote

numbers, range 