-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1 +1,27 @@ | ||
# calculator-class-exercise | ||
|
||
|
||
|
||
Tasks: | ||
1. Clone this repo locally | ||
|
||
2. Create a NEW local branch. Name it like JC-038-calc, where JC are your initials and 038 is the last three digits | ||
of your netid. (Or pick three random numbers instead of your netid digits if you prefer.) | ||
|
||
git checkout -b JC-038-calc | ||
|
||
3. Install pytest if needed. | ||
|
||
python -m pip install pytest | ||
|
||
4. Create Unit Tests to properly unit test the calculator.py code. You may not change ANYTHING | ||
in calculator.py. You can only edit test.py. Using pytest is much easier that unittest. | ||
|
||
5. Push you local branch to github | ||
|
||
git add test.py | ||
git commit -m "More unit tests" | ||
git push --set-upstream origin JC-038-calc | ||
|
||
6. Submit a pull request (PR) and assign it to me | ||
|
This file contains 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,53 @@ | ||
# Python program for simple calculator | ||
# https://www.geeksforgeeks.org/make-simple-calculator-using-python/ | ||
|
||
# Function to add two numbers | ||
def add(num1, num2): | ||
return num1 + num2 | ||
|
||
# Function to subtract two numbers | ||
def subtract(num1, num2): | ||
return num1 - num2 | ||
|
||
# Function to multiply two numbers | ||
def multiply(num1, num2): | ||
return num1 * num2 | ||
|
||
# Function to divide two numbers | ||
def divide(num1, num2): | ||
return num1 / num2 | ||
|
||
def run_calc(): | ||
print("Please select operation -\n" \ | ||
"1. Add\n" \ | ||
"2. Subtract\n" \ | ||
"3. Multiply\n" \ | ||
"4. Divide\n") | ||
|
||
|
||
# Take input from the user | ||
select = int(input("Select operations form 1, 2, 3, 4 :")) | ||
|
||
number_1 = int(input("Enter first number: ")) | ||
number_2 = int(input("Enter second number: ")) | ||
|
||
if select == 1: | ||
print(number_1, "+", number_2, "=", | ||
add(number_1, number_2)) | ||
|
||
elif select == 2: | ||
print(number_1, "-", number_2, "=", | ||
subtract(number_1, number_2)) | ||
|
||
elif select == 3: | ||
print(number_1, "*", number_2, "=", | ||
multiply(number_1, number_2)) | ||
|
||
elif select == 4: | ||
print(number_1, "/", number_2, "=", | ||
divide(number_1, number_2)) | ||
else: | ||
print("Invalid input") | ||
|
||
if __name__ == "__main__": | ||
run_calc() |
This file contains 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,9 @@ | ||
# test_with_pytest.py | ||
|
||
# import pytest | ||
|
||
from calculator import add | ||
|
||
def test_add(): | ||
assert add(2, 2) == 4 | ||
|