Install pytest:
pip install pytest
We'll use pytest to test the Python functions we write below.
In your home directory, make a folder called Development, if it doesn't exist. This is where we will keep all of the code for the class. Next, make sure that you are inside that folder, by checking the output of the following command:
pwdIf pwd shows that you are in a different directory, run cd ~/Development and check with pwd again.
Next, clone this repository by clicking the green button in the upper right corner, selecting SSH and copying the string that looks like git@github.com:code4policy/<REPO-NAME>.git (<REPO-NAME> will be the name of your repository). Then, in the terminal run the following:
git clone git@github.com:code4policy/<REPO-NAME>.git
Note that by default, git will clone the repository into a folder with name <REPO-NAME>. After the repo is cloned, open that directory (use cd).
-
create a new branch in your git repo called "calculator"
-
inside that branch create a new file called
calculator.py -
Write 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.03s -
Commit to git
git commit -m "add functions to calculator"and push the change to github.git push -
At 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.py -
Make 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 pull -
Delete your local version of the calculator branch
git branch -D calculator -
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.
-
create a new branch in your
assignmentsgit repo called "js-calculator" -
inside that branch create a new file called
calculator.js -
Write (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 push -
At 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") var x = 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.js -
Make 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 pull -
Delete your local version of the js-calculator branch
git branch -D js-calculator