Read through the instructions below then use the checklist to tick off the sub-tasks as you complete them.
Instructions
NB Code chunks below can be copied using the button that appears on the top right of the code box when you move the
mouse over it.
Create Branch
Create a branch locally from the main branch to work on this task. Try using the suggested nomenclature of
<github_username>/<issue_number>-<short_description>, e.g.
git switch -c "ns-rse/3-zero-division"
Add a try: ... except: ... to capture ZeroDivisionError
Replace line 55 in the pythonmaths/arithmetic.py file which currently reads.
With the following code which raises a custom exception message.
try:
return x / y
except ZeroDivisionError as e:
raise ZeroDivisionError(
"You can not divide by 0, please choose another value for 'y'."
) from e
Add a test to check the exception is raised
Add the following to the tests/test_arithmetic.py which checks that the exception is raised.
def test_divide_zero_division_exception() -> None:
"""Test that a ZeroDivisionError is raised by the divide() function."""
with pytest.raises(ZeroDivisionError):
arithmetic.divide(2, 0)
Save, stage, commit your changes
NB Make sure to replace the message in the second line with a meaningful message.
git add -u # This will add all files that are under version control and have been modified
git commit -m "feature: add zero division error"
Push to origin
The changes only exist on your local branch and there is no tracking branch on the remote origin (GitHub). The
following will create a tracking branch upstream and push to it all in one go.
NB You will have to substitute the <local_branch_name> for whatever you opted to call the branch in the first
step.
Create a Pull Request
Navigate to your repository and create a Pull Request, adding your collaborator as a reviewer.
Remember you can use the GitHub
Keywords
to automatically close the related issue.
Address any feedback or errors that arise in the GitHub Actions.
Merge the Pull Request
Once approved merge the pull request and delete your local branch.
git switch main
git pull
git branch -d ns-rse/3-zero-division
Read through the instructions below then use the checklist to tick off the sub-tasks as you complete them.
try: ... except: ...to thedivide functionin thepythonmaths/arithmetic.pymodule.0as denominator.Instructions
NB Code chunks below can be copied using the button that appears on the top right of the code box when you move the
mouse over it.
Create Branch
Create a branch locally from the
mainbranch to work on this task. Try using the suggested nomenclature of<github_username>/<issue_number>-<short_description>, e.g.git switch -c "ns-rse/3-zero-division"Add a
try: ... except: ...to captureZeroDivisionErrorReplace line 55 in the
pythonmaths/arithmetic.pyfile which currently reads.With the following code which raises a custom exception message.
Add a test to check the exception is raised
Add the following to the
tests/test_arithmetic.pywhich checks that the exception is raised.Save, stage, commit your changes
NB Make sure to replace the message in the second line with a meaningful message.
Push to
originThe changes only exist on your local branch and there is no tracking branch on the remote
origin(GitHub). Thefollowing will create a tracking branch upstream and push to it all in one go.
NB You will have to substitute the
<local_branch_name>for whatever you opted to call the branch in the firststep.
Create a Pull Request
Navigate to your repository and create a Pull Request, adding your collaborator as a reviewer.
Remember you can use the GitHub
Keywords
to automatically close the related issue.
Address any feedback or errors that arise in the GitHub Actions.
Merge the Pull Request
Once approved merge the pull request and delete your local branch.