Wordy in Python
Parse and evaluate simple math word problems returning the answer as an integer.
1  exercism fetch python wordy

Wordy
Parse and evaluate simple math word problems returning the answer as an integer.
Iteration 1 — Addition
Add two numbers together.
What is 5 plus 13?
Evaluates to 18.
Handle large numbers and negative numbers.
Iteration 2 — Subtraction, Multiplication and Division
Now, perform the other three operations.
What is 7 minus 5?
2
What is 6 multiplied by 4?
24
What is 25 divided by 5?
5
Iteration 3 — Multiple Operations
Handle a set of operations, in sequence.
Since these are verbal word problems, evaluate the expression from lefttoright, ignoring the typical order of operations.
What is 5 plus 13 plus 6?
24
What is 3 plus 2 multiplied by 3?
15 (i.e. not 9)
Bonus — Exponentials
If you'd like, handle exponentials.
What is 2 raised to the 5th power?
32
Exception messages
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include a message.
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
raise Exception
, you should write:
1 
raise Exception("Meaningful message indicating the source of the error")

Running the tests
To run the tests, run the appropriate command below (why they are different):
 Python 2.7:
py.test wordy_test.py
 Python 3.3+:
pytest wordy_test.py
Alternatively, you can tell Python to run the pytest module (allowing the same command to be used regardless of Python version):
python m pytest wordy_test.py
Common pytest
options

v
: enable verbose output 
x
: stop running tests on first failure 
ff
: run failures from previous test before running other test cases
For other options, see python m pytest h
Submitting Exercises
Note that, when trying to submit an exercise, make sure the solution is in the $EXERCISM_WORKSPACE/python/wordy
directory.
You can find your Exercism workspace by running exercism debug
and looking for the line that starts with Workspace
.
For more detailed information about running tests, code style and linting, please see the help page.
Source
Inspired by one of the generated questions in the Extreme Startup game. https://github.com/rchatley/extreme_startup
Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.