Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joc22038 committed Nov 22, 2023
1 parent 11c2e4d commit a132b56
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
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

53 changes: 53 additions & 0 deletions calculator.py
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()
9 changes: 9 additions & 0 deletions test.py
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

0 comments on commit a132b56

Please sign in to comment.