From 7160c6fd2ad52dc7c7e117c1e59ff7de4821603e Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Fri, 25 Nov 2022 22:14:47 +0000 Subject: - Added solutions to the task 1 of week 192. --- challenge-192/mohammad-anwar/python/ch-1.py | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 challenge-192/mohammad-anwar/python/ch-1.py (limited to 'challenge-192/mohammad-anwar/python') diff --git a/challenge-192/mohammad-anwar/python/ch-1.py b/challenge-192/mohammad-anwar/python/ch-1.py new file mode 100644 index 0000000000..3ff80be425 --- /dev/null +++ b/challenge-192/mohammad-anwar/python/ch-1.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +''' + +Week 192: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-192 + +Task #1: Binary Flip + + You are given a positive integer, $n. + + Write a script to find the binary flip. + +''' + +import unittest + +def binaryFlip(n) -> int: + return int(''.join(['1' if i == '0' else '0' for i in "{0:b}".format(n)]),2) + +# +# +# Unit test class + +class TestBinaryFlip(unittest.TestCase): + def test_binaryFlip(self): + self.assertEqual(binaryFlip(5), 2, 'Example 1') + self.assertEqual(binaryFlip(4), 3, 'Example 2') + self.assertEqual(binaryFlip(6), 1, 'Example 3') + +unittest.main() -- cgit