From 20668657d4587d0f6d191da8c7f658ae6c949581 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 27 Dec 2021 11:59:06 +0000 Subject: - Added Python solution to the task "Dot Product" of week 145. --- challenge-145/mohammad-anwar/python/ch-1.py | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 challenge-145/mohammad-anwar/python/ch-1.py diff --git a/challenge-145/mohammad-anwar/python/ch-1.py b/challenge-145/mohammad-anwar/python/ch-1.py new file mode 100644 index 0000000000..de600fc0a5 --- /dev/null +++ b/challenge-145/mohammad-anwar/python/ch-1.py @@ -0,0 +1,40 @@ +#!/usr/bin/python3 + +''' + +Week 145: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-145 + +Task #1: Dot Product + + You are given 2 arrays of same size, @a and @b. + + Write a script to implement Dot Product. + +''' + +import unittest + +def dot_product(a, b): + + if len(a) == len(b): + dp = 0 + for i in range(0, len(a)): + dp += a[i] * b[i] + + return dp; + +# +# +# Unit test class + +class TestJortSort(unittest.TestCase): + + def test_example(self): + self.assertEqual( + dot_product([1,2,3], [4,5,6]), + 32, + 'Example') + +unittest.main() -- cgit