From a132b5605ef5b0414f77ddca8fdb452f02c49a16 Mon Sep 17 00:00:00 2001 From: Jon Clark Date: Tue, 21 Nov 2023 19:25:27 -0500 Subject: [PATCH] Initial commit --- README.md | 26 +++++++++++++++++++++++++ calculator.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ test.py | 9 +++++++++ 3 files changed, 88 insertions(+) create mode 100644 calculator.py create mode 100644 test.py diff --git a/README.md b/README.md index 6229d6c..b3ce264 100644 --- a/README.md +++ b/README.md @@ -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 + diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000..f683f95 --- /dev/null +++ b/calculator.py @@ -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() \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..221e29f --- /dev/null +++ b/test.py @@ -0,0 +1,9 @@ +# test_with_pytest.py + +# import pytest + +from calculator import add + +def test_add(): + assert add(2, 2) == 4 +