PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'''
binary-bcd algorithm for Python
Coded by Marco Abrate 2017
Challenge by sayan chandra
Task:
if number of 1's in binary is equal to number of 1's in bcd ''upto that length''of binary (from right to left)
print the number,
print bcd eqiv,
print binary eqiv..
eg: 18---bcd 00011000 ( two 1's)
18--binary 10010 ( two 1's)
eg: 179---bcd 0001 01111001 ( five 1's)
179--binary 10110011 (five 1's)
'''
def sod(string):
ll=[]
ll+=string
s=0
for i in ll:
s+=int(i)
return s
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run