|
| 1 | +# Armstrong Numbers |
| 2 | + |
| 3 | +An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits. |
| 4 | + |
| 5 | +For example: |
| 6 | + |
| 7 | +- 9 is an Armstrong number, because `9 = 9^1 = 9` |
| 8 | +- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 1` |
| 9 | +- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153` |
| 10 | +- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190` |
| 11 | + |
| 12 | +Write some code to determine whether a number is an Armstrong number. |
| 13 | + |
| 14 | + |
| 15 | +## Exception messages |
| 16 | + |
| 17 | +Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to |
| 18 | +indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not |
| 19 | +every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include |
| 20 | +a message. |
| 21 | + |
| 22 | +To raise a message with an exception, just write it as an argument to the exception type. For example, instead of |
| 23 | +`raise Exception`, you should write: |
| 24 | + |
| 25 | +```python |
| 26 | +raise Exception("Meaningful message indicating the source of the error") |
| 27 | +``` |
| 28 | + |
| 29 | +## Running the tests |
| 30 | + |
| 31 | +To run the tests, run `pytest armstrong_numbers_test.py` |
| 32 | + |
| 33 | +Alternatively, you can tell Python to run the pytest module: |
| 34 | +`python -m pytest armstrong_numbers_test.py` |
| 35 | + |
| 36 | +### Common `pytest` options |
| 37 | + |
| 38 | +- `-v` : enable verbose output |
| 39 | +- `-x` : stop running tests on first failure |
| 40 | +- `--ff` : run failures from previous test before running other test cases |
| 41 | + |
| 42 | +For other options, see `python -m pytest -h` |
| 43 | + |
| 44 | +## Submitting Exercises |
| 45 | + |
| 46 | +Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/armstrong-numbers` directory. |
| 47 | + |
| 48 | +You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`. |
| 49 | + |
| 50 | +For more detailed information about running tests, code style and linting, |
| 51 | +please see [Running the Tests](http://exercism.io/tracks/python/tests). |
| 52 | + |
| 53 | +## Source |
| 54 | + |
| 55 | +Wikipedia [https://en.wikipedia.org/wiki/Narcissistic_number](https://en.wikipedia.org/wiki/Narcissistic_number) |
| 56 | + |
| 57 | +## Submitting Incomplete Solutions |
| 58 | + |
| 59 | +It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
0 commit comments