-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[State of Tic Tac Toe]: Added missing instruction append for raising errors. #4242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
exercises/practice/state-of-tic-tac-toe/.docs/instructions.append.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Instructions append | ||
|
|
||
| ## Exception messages | ||
|
|
||
| Sometimes it is necessary to [raise an exception][raising-exceptions]. | ||
| When you do this, you should always 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. | ||
| For situations where you know that the error source will be a certain type, you can choose to raise one of the [built in error types][error-base-classes], but should still include a meaningful message. | ||
|
|
||
|
|
||
| A valid game of `Tic Tac Toe` ends when one player wins. | ||
| If both players are in a winning state, or there is a mismatch between the winner and their number of moves, this exercise expects you to use the [raise statement][raise] and "throw" a `ValueError` in your solution. | ||
| Your code is also expected to throw a `ValueError` if one player is assessed as playing two turns in a row, or playing the first move when they were assigned to play the second move. | ||
|
|
||
|
|
||
| To raise a `ValueError` with a message, write the message as an argument to the `exception` type: | ||
|
|
||
| ```python | ||
| # Example when player X goes before player O. | ||
| raise ValueError("Wrong turn order: O started") | ||
|
|
||
| # Example when player X goes twice. | ||
| raise ValueError("Wrong turn order: X went twice") | ||
|
|
||
| # Example when player X wins AND player O wins. | ||
| raise ValueError("Impossible board: game should have ended after the game was won") | ||
| ``` | ||
|
|
||
| The tests will check for an exact error message match, so please read the expected results carefully. | ||
|
|
||
| [raising-exceptions]: https://docs.python.org/3/tutorial/errors.html#raising-exceptions | ||
| [error-base-classes]: https://docs.python.org/3/library/exceptions.html#base-classes | ||
| [raise]: https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.