Question: I want to write a function that checks if a syntax is correct. The part of the syntax I struggle with is this one:

```
< number >: := 2 | 3 | ... 

```

I have defined it as:

```
def number(q):     
    letter = q.dequeue()    
    if int(letter) >= 2:         
        return     
    raise error("Number must be greater than 2") 

```

Where the input is q (Linked queue) containing characters. What this
function is supposed to do is check whether the integer in the input is greater than two. The integers could be "2","100", "12" and so on. However, what I think my function does is it only looks for the first integer that comes up in the input and that's why It doesn't work the way it's supposed to.

The way it's supposed to work: if the function finds a "0" in the beginning of the input(ex:H010) it should give the error "Number must be greater than 2". But for every other case, if the digits start with anything that isn't "0" the function should read through every digit of the input before deciding if the number is bigger or smaller than two.

If I were to write the input "H122", the function should be able to read the whole number "122" and and not only the first which is "1".
My question is, how do I make this work?

Answer: 
Assuming you get the entire string, you can do it this way:

```
def validate(q):
    word = q.dequeue()
    if word[0] != 'H':
        raise error("Does not start with H.")
    if not word[1:].isdigit():
        raise error("Value is not numeric.")
    val = int(word[1:])
    if val < 2:
        raise error("Number must be greater than or equal to 2.")
    return val

```
I'm not entirely sure about what type `q` is, or what the `H` in the string represents for example, but this should work for the cases outlined in the question:

```py
def number(q):
    nums = filter(str.isdigit, q)
    try:
        first_num = next(nums)
    except StopIteration:
        raise error('Enter a string with numbers')
    if first_num == '0':
        raise error("Number must be greater than 2")
    return int(''.join([first_num, *nums]))

# raises errors
# number('abc')
# number('H012')

assert number('abc123') == 123
assert number('aaaaah123heeeellllpp45') == 12345
assert number('H122') == 122
assert number('2') == 2
assert number('100') == 100

```