aboutsummaryrefslogtreecommitdiff
path: root/challenge-140/cristian-heredia/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-11-24 02:09:10 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-11-24 02:09:10 +0000
commitfc7fde518df32cf8a39265451adfda5966592761 (patch)
treed77c7b02951f7689ba031e6ee70aaebaa9cac097 /challenge-140/cristian-heredia/python/ch-1.py
parent72b8666ef4a74dc59c3f95a2f76796e1f531c07d (diff)
downloadperlweeklychallenge-club-fc7fde518df32cf8a39265451adfda5966592761.tar.gz
perlweeklychallenge-club-fc7fde518df32cf8a39265451adfda5966592761.tar.bz2
perlweeklychallenge-club-fc7fde518df32cf8a39265451adfda5966592761.zip
- Added solution by Cristina Heredia.
Diffstat (limited to 'challenge-140/cristian-heredia/python/ch-1.py')
-rw-r--r--challenge-140/cristian-heredia/python/ch-1.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-140/cristian-heredia/python/ch-1.py b/challenge-140/cristian-heredia/python/ch-1.py
new file mode 100644
index 0000000000..91f14c4d39
--- /dev/null
+++ b/challenge-140/cristian-heredia/python/ch-1.py
@@ -0,0 +1,28 @@
+"""
+
+ TASK #1 › Add Binary
+ Submitted by: Mohammad S Anwar
+ You are given two decimal-coded binary numbers, $a and $b.
+
+ Write a script to simulate the addition of the given binary numbers.
+
+ The script should simulate something like $a + $b. (operator overloading)
+
+ Example 1
+ Input: $a = 11; $b = 1;
+ Output: 100
+ Example 2
+ Input: $a = 101; $b = 1;
+ Output: 110
+ Example 3
+ Input: $a = 100; $b = 11;
+ Output: 111
+"""
+
+
+a = '11'
+b = '1'
+
+# binary to decimal, add, decimal to binary
+add = bin(int(a,2) + int(b,2)).replace("0b", "")
+print(add) \ No newline at end of file