Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions basic/listoperations.py
Original file line number Diff line number Diff line change
@@ -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
"""

59 changes: 59 additions & 0 deletions basic/mathematics.py
Original file line number Diff line number Diff line change
@@ -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


32 changes: 32 additions & 0 deletions basic/test/test_listoperations.py
Original file line number Diff line number Diff line change
@@ -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"]



3 changes: 3 additions & 0 deletions basic/test/test_mathematics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import unittest

doctest_modules = ['basic.mathematics']