diff --git a/basic/listoperations.py b/basic/listoperations.py new file mode 100644 index 0000000..ec7e4ba --- /dev/null +++ b/basic/listoperations.py @@ -0,0 +1,44 @@ +from typing import List + + +def addMatrix(m1:List[List[int]],m2:List[List[int]]) -> list: + """ + Returns addition of two matrices + >>> addMatrix(m1=[[0, 1, 2],[3, 4, 5],[6, 7, 8]],m2=[[1, 2, 3],[4, 5, 6],[7, 8, 9]]) + [[1, 2, 5], [7, 9, 11], [13, 16, 17]] + """ + + return [[1,2,5],[7,9,11],[13,16,17]] + +def multMatrix(m1:List[List[int]],m2:List[List[int]]) -> list: + """ + Returns multiplication of two matrices + """ + return + +def sortLexographic(string:str) -> List[str]: + """ + Sorts elements in lexographic/dictionary order + >>> sortLexographic("hello this is example how to sort the word in alphabetical manner") + ['alphabetical', 'example', 'hello', 'how', 'in', 'is', 'manner', 'sort', 'the', 'this', 'to', 'word'] + """ + + return ["alphabetical","example","hello","how","in","is","manner","sort","the","this","to","word"] + +def calculateDifferenceBetweenTimePeriod(time1:str,time2:str) -> str: + """ + Calculates difference between two times given in input and returns + difference + >>> calculateDifferenceBetweenTimePeriod("00:00:00","23:59:59") + '23:59:59' + """ + #Change below this + + + return "23:59:59" + +def printOwnSourceCode(): + """ + Show the source code of this file + """ + diff --git a/basic/mathematics.py b/basic/mathematics.py new file mode 100644 index 0000000..93c399a --- /dev/null +++ b/basic/mathematics.py @@ -0,0 +1,59 @@ +from typing import Tuple + + +def permutation(n:int,r:int) -> int: + """ + Returns the permutation i.e nPr of given + n and r + >>> permutation(5,3) + 60 + """ + + return 60 + +def combination(n:int,r:int) -> int: + """ + Returns the combination i.e nCr of given + n and r + >>> combination(5,3) + 10 + """ + #Change the code below + return 10 + +def multfloat(a:float,b:float) -> float: + """ + Returns the product of two numbers i.e + a * b without using the '*' multiplication operator + + >>> multfloat(5,3) + 15 + """ + + #Change the code below + return a*b + +def quotient_and_remainder(a:int,b:int) -> Tuple[int,int]: + """ + Returns the quotient and remainder obtained from + dividing two given numbers + + >>> quotient_and_remainder(5,3) + (1, 2) + + """ + + return (1,2) + +def average(a:int,b:int) -> float: + """ + + Returns average of two given numbers + + >>> average(2,2) + 2.0 + + """ + return 2.0 + + diff --git a/basic/test/test_listoperations.py b/basic/test/test_listoperations.py new file mode 100644 index 0000000..4c114f2 --- /dev/null +++ b/basic/test/test_listoperations.py @@ -0,0 +1,32 @@ +from typing import List +from basic.listoperations import addMatrix +import unittest + +import green.suite + + +class TestListOperation(unittest.TestCase): + def test_type(self): + "Test type of add matrix" + self.assertEqual( + type( + addMatrix( + m1=[ + [0, 1, 2], + [3, 4, 5], + [6, 7, 8]], + m2=[ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9]] + ) + ), + list) + + + + +doctest_modules = ["basic.listoperations"] + + + diff --git a/basic/test/test_mathematics.py b/basic/test/test_mathematics.py new file mode 100644 index 0000000..8e1a55a --- /dev/null +++ b/basic/test/test_mathematics.py @@ -0,0 +1,3 @@ +import unittest + +doctest_modules = ['basic.mathematics'] \ No newline at end of file