|
| 1 | +# Reverse String |
| 2 | + |
| 3 | +Reverse a string |
| 4 | + |
| 5 | +For example: |
| 6 | +input: "cool" |
| 7 | +output: "looc" |
| 8 | + |
| 9 | + |
| 10 | +## Exception messages |
| 11 | + |
| 12 | +Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to |
| 13 | +indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not |
| 14 | +every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include |
| 15 | +a message. |
| 16 | + |
| 17 | +To raise a message with an exception, just write it as an argument to the exception type. For example, instead of |
| 18 | +`raise Exception`, you should write: |
| 19 | + |
| 20 | +```python |
| 21 | +raise Exception("Meaningful message indicating the source of the error") |
| 22 | +``` |
| 23 | + |
| 24 | +## Running the tests |
| 25 | + |
| 26 | +To run the tests, run `pytest reverse_string_test.py` |
| 27 | + |
| 28 | +Alternatively, you can tell Python to run the pytest module: |
| 29 | +`python -m pytest reverse_string_test.py` |
| 30 | + |
| 31 | +### Common `pytest` options |
| 32 | + |
| 33 | +- `-v` : enable verbose output |
| 34 | +- `-x` : stop running tests on first failure |
| 35 | +- `--ff` : run failures from previous test before running other test cases |
| 36 | + |
| 37 | +For other options, see `python -m pytest -h` |
| 38 | + |
| 39 | +## Submitting Exercises |
| 40 | + |
| 41 | +Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/reverse-string` directory. |
| 42 | + |
| 43 | +You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`. |
| 44 | + |
| 45 | +For more detailed information about running tests, code style and linting, |
| 46 | +please see [Running the Tests](http://exercism.io/tracks/python/tests). |
| 47 | + |
| 48 | +## Source |
| 49 | + |
| 50 | +Introductory challenge to reverse an input string [https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb](https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb) |
| 51 | + |
| 52 | +## Submitting Incomplete Solutions |
| 53 | + |
| 54 | +It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
0 commit comments