diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-12-27 11:59:06 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-12-27 11:59:06 +0000 |
| commit | 20668657d4587d0f6d191da8c7f658ae6c949581 (patch) | |
| tree | b3f8d64285419f9262e7f04746dd384beaf70c0e | |
| parent | 01cfbda737e866e75f9ecaaa91ed89b385922f9b (diff) | |
| download | perlweeklychallenge-club-20668657d4587d0f6d191da8c7f658ae6c949581.tar.gz perlweeklychallenge-club-20668657d4587d0f6d191da8c7f658ae6c949581.tar.bz2 perlweeklychallenge-club-20668657d4587d0f6d191da8c7f658ae6c949581.zip | |
- Added Python solution to the task "Dot Product" of week 145.
| -rw-r--r-- | challenge-145/mohammad-anwar/python/ch-1.py | 40 |
1 files changed, 40 insertions, 0 deletions
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() |
