Skip to content

Commit

Permalink
added calculator codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald committed Dec 2, 2020
0 parents commit de41af8
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
print("Hello!")


print("this is the edited branch")


print("This is the addon for feature 1")

print("i am adding this line!!!")

print("Hello this is adding new feature1")

#add new comment

Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions mycalculator/my_calculator_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from my_calculator_functions import *

class MyCalculator(object):

def __init__(self):
self._answer = 0.0


def last_answer(self):
return self._answer

def do_math(self, *arg, function):
self._answer = function(*arg)
return self._answer


def add(self, *arg):
return self.do_math(*arg, add)

def subtract(self, *arg):
return self.do_math(*arg, subtract)

def multiply(self, *arg):
return self.do_math(*arg, multiply)

def divide(self, *arg):
return self.do_math(*arg, divide)
63 changes: 63 additions & 0 deletions mycalculator/my_calculator_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
def add(*arg):
if(len(arg)>10):
print("this is another easter")
return "Error: >10 Values"


if(len(arg) > 10):
print("Error >10 values given!")
return "Error: >10 Values"

print("Adding",len(arg),"numbers")
result = 0
for n in arg:
result = result + n

print("Add result is", result)
return result

def subtract(*arg):
if(len(arg) > 10):
print("Error >10 values given!")
return "Error: >10 Values"
print("Subtracting",len(arg),"numbers")
result = arg[0]
for n in range(1, len(arg)):
result = result - arg[n]

print("Subtract result is", result)
return result

def multiply(*arg):
if(len(arg) > 10):
print("Error >10 values given!")
return "Error: >10 Values"
print("Multipling",len(arg),"numbers")
result = arg[0]
for n in range(1, len(arg)):
result = result * arg[n]

print("Multiply result is", result)
return result

def divide(*arg):
if(len(arg) > 10):
print("Error >10 values given!")
return "Error: >10 Values"
print("Dividing", len(arg),"numbers")

result = arg[0]
try:
for n in range(1, len(arg)):
result = result / arg[n]

print("Divide result is", result)
return result
except ZeroDivisionError:
print("Division by Zero Error at number", n+1)
return ZeroDivisionError





30 changes: 30 additions & 0 deletions test_my_calculator_functions_addition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
from mycalculator.my_calculator_functions import *

'''
@pytest.mark.parametrize("a,b,result",[(1,2,3), (2,4,6)])
def test_add(a,b,result):
value = add(a,b)
assert value == result
def test_add_negative_positive():
value = add(-1,2,3)
assert value == 4
def test_add_negative_negative():
value = add(-1,-2)
assert value == -5
'''

def test_over_ten_variables():#add comment
value = add(1,2,3,4,5,6,7,8,9,10,11,12)
assert value == "Error: >10 Values"

def test_multiplication():
value = multiply(1,1,1,1,1,1,1,1,1,1)
assert value == 1

def test_multiplication_over_ten():
value = multiply(1,1,1,1,1,1,1,1,1,1,1)
assert value == "Error: >10 Values"

0 comments on commit de41af8

Please sign in to comment.