|
| 1 | +# Matrix |
| 2 | + |
| 3 | +Given a string representing a matrix of numbers, return the rows and columns of |
| 4 | +that matrix. |
| 5 | + |
| 6 | +So given a string with embedded newlines like: |
| 7 | + |
| 8 | +```text |
| 9 | +9 8 7 |
| 10 | +5 3 2 |
| 11 | +6 6 7 |
| 12 | +``` |
| 13 | + |
| 14 | +representing this matrix: |
| 15 | + |
| 16 | +```text |
| 17 | + 1 2 3 |
| 18 | + |--------- |
| 19 | +1 | 9 8 7 |
| 20 | +2 | 5 3 2 |
| 21 | +3 | 6 6 7 |
| 22 | +``` |
| 23 | + |
| 24 | +your code should be able to spit out: |
| 25 | + |
| 26 | +- A list of the rows, reading each row left-to-right while moving |
| 27 | + top-to-bottom across the rows, |
| 28 | +- A list of the columns, reading each column top-to-bottom while moving |
| 29 | + from left-to-right. |
| 30 | + |
| 31 | +The rows for our example matrix: |
| 32 | + |
| 33 | +- 9, 8, 7 |
| 34 | +- 5, 3, 2 |
| 35 | +- 6, 6, 7 |
| 36 | + |
| 37 | +And its columns: |
| 38 | + |
| 39 | +- 9, 5, 6 |
| 40 | +- 8, 3, 6 |
| 41 | +- 7, 2, 7 |
| 42 | + |
| 43 | +In this exercise you're going to create a **class**. _Don't worry, it's not as complicated as you think!_ |
| 44 | + |
| 45 | +- [**A First Look at Classes**](https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes) from the Python 3 documentation. |
| 46 | +- [**How to Define a Class in Python**](https://realpython.com/python3-object-oriented-programming/#how-to-define-a-class-in-python) from the Real Python website. |
| 47 | +- [**Data Structures in Python**](https://docs.python.org/3/tutorial/datastructures.html) from the Python 3 documentation. |
| 48 | + |
| 49 | + |
| 50 | +## Exception messages |
| 51 | + |
| 52 | +Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to |
| 53 | +indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not |
| 54 | +every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include |
| 55 | +a message. |
| 56 | + |
| 57 | +To raise a message with an exception, just write it as an argument to the exception type. For example, instead of |
| 58 | +`raise Exception`, you should write: |
| 59 | + |
| 60 | +```python |
| 61 | +raise Exception("Meaningful message indicating the source of the error") |
| 62 | +``` |
| 63 | + |
| 64 | +## Running the tests |
| 65 | + |
| 66 | +To run the tests, run `pytest matrix_test.py` |
| 67 | + |
| 68 | +Alternatively, you can tell Python to run the pytest module: |
| 69 | +`python -m pytest matrix_test.py` |
| 70 | + |
| 71 | +### Common `pytest` options |
| 72 | + |
| 73 | +- `-v` : enable verbose output |
| 74 | +- `-x` : stop running tests on first failure |
| 75 | +- `--ff` : run failures from previous test before running other test cases |
| 76 | + |
| 77 | +For other options, see `python -m pytest -h` |
| 78 | + |
| 79 | +## Submitting Exercises |
| 80 | + |
| 81 | +Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/matrix` directory. |
| 82 | + |
| 83 | +You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`. |
| 84 | + |
| 85 | +For more detailed information about running tests, code style and linting, |
| 86 | +please see [Running the Tests](http://exercism.io/tracks/python/tests). |
| 87 | + |
| 88 | +## Source |
| 89 | + |
| 90 | +Warmup to the `saddle-points` warmup. [http://jumpstartlab.com](http://jumpstartlab.com) |
| 91 | + |
| 92 | +## Submitting Incomplete Solutions |
| 93 | + |
| 94 | +It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
0 commit comments