Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)

```        def solve(question):

tokens = re.sub(r'[\?,]', '', question).lower().split(' ')
operator = 1
index = -1

#    'What is 10 plus 1?' - 11
#    '1 + 3 is what?' - 4
if 'plus' in tokens or '+' in tokens or 'add' in tokens:

# Find the location of the operator.
index = tokens.index('plus') if 'plus' in tokens else \
tokens.index('+') if '+' in tokens else \
None

if index is None:
return None

operator = 1

# Subtraction:
#    'What is ten - 3?' - 7
#    '8 minus 4 is what?' - 4
elif 'minus' in tokens or '-' in tokens or 'subtract' in tokens:

# Find the location of the operator.
index = tokens.index('minus') if 'minus' in tokens else \
tokens.index('-') if '-' in tokens else \
tokens.index('subtract') if 'subtract' in tokens else \
None

if index is None:
return None

operator = -1

else:
return None

# Get the tokens before and after the operator (should be numbers).
before = tokens[index - 1]
before = int(before) if is_num(before) else numbers[before] if before in numbers else None
after = tokens[index + 1]
after = int(after) if is_num(after) else numbers[after] if after in numbers else None

if before is None or after is None:
return None

# Return the total.
return str(before + operator * after)
```

```                answer = DigitPattern.solve(question)