As usual, clone this repo to your assignments directory (or wherever you like to work).
We'll use the pytest Python library to test the functions we write below. Let's install pytest in a Python virtual environment:
python3 -m venv virtualenv # create a python virtual environment
source ./virtualenv/bin/activate # activate the virtual environment
pip install pytest # install the pytest package
create a new branch in your git repo called
calculatorinside that branch create a new file called
calculator.pyWrite a program that defines four functions (multiply, add, subtract, and divide). These functions should not print anything, they should simply perform a mathematical operation on the two arguments and return the value.
You can test whether your functions work by running
pytestin the current directory. Don't worry if you don't pass all the tests! At this step we only expect you to pass tests foradd,subtract,multiply, anddivide) You should ideally see something in the ouptut that looks like2 failed, 4 passed in 0.03sCommit to git
git commit -m "add functions to calculator"and push the change to github.git pushAt the bottom of the file, Call the function and print a line explaining what is happening. Like this:
print("I'm going use the calculator functions to multiply 5 and 6") x=multiply(5,6) print(x)
Commit this change and explain what you just did in the commit message
Run the file with the following command to make sure your python is all right:
python3 calculator.pyMake sure everything works correctly and issue a pull request on github back to the main branch with a message explaining what changes you made in this branch.
Accept the pull request into the main branch and delete the
calculatorbranch on github.Checkout the main branch, and pull the version of main with the calculator branch merged
git checkout main git pullDelete your local version of the calculator branch
git branch -D calculatorCreate a new branch from
main. In the new branch, add two more functions,squareandcube. both should take a single number as an argument and return the number raised to the appropriate power.Make a function called
square_n_timesthat takes two arguments,numberandn. Have the function square the numberntimes and return the sum.PR the new branch to
main. Yourcalcluator.pyinmainshould now have functions for addition, subtraction, multiplication, division, squaring, cubing, and adding squaresntimes.
On WSL: sudo apt-get install npm
On Mac: brew install npm
create a new branch
js-calculatorinside that branch create a new file called
calculator.jsWrite (in javascript) a program that defines four functions (multiply, add, subtract, and divide). These functions should not print anything, they should simply perform a mathematical operation on the two arguments and return the value.
Commit to git
git commit -m "add functions to calculator"and push the change to github.git pushAt the bottom of the file, Call the function and print a line explaining what is happening. Like this:
console.log("I'm going use the calculator functions to multiply 5 and 6")varx=multiply(5,6)console.log(x)
Commit this change and explain what you just did in the commit message
Run the file with the following command to make sure your JavaScript is all right:
node calculator.jsMake sure everything works correctly and issue a pull request on github back to the main branch with a message explaining what changes you made in this branch.
Accept the pull request into the main branch and delete the
js-calculatorbranch on github.Checkout the main branch, and pull the version of main with the calculator branch merged
git checkout main git pullDelete your local version of the js-calculator branch
git branch -D js-calculator