forked from Srinivas11789/AlgorithmNuggets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path101_8.py
More file actions
28 lines (23 loc) · 800 Bytes
/
101_8.py
File metadata and controls
28 lines (23 loc) · 800 Bytes
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
# 101 Challenge -> Binary Challenge
# Lesson:
# * Binary number conversion in python is easy with bin() function but it adds a "0b" in the front of the string
# * Try to bypass the 0b for proper functionality
# * Max decision loop => (If max >) should be placed properly for the answer.
# * Place the decision loop logic so that you could fetch the right output. For instance placing the resp if loop in the beginning of for loop throws wrong ans
#!/bin/python
import sys
n = int(raw_input().strip())
binaryn = bin(n)[2:]
#print binaryn
result = {"0":0, "1":0}
max = 0
#binaryn = str(n)
for char in binaryn:
if char == "1":
result["1"] += 1
if result["1"] > max:
max = result["1"]
if char == "0":
result["0"] += 1
result["1"] = 0
print max