Python Day 10: Binary Numbers




Given a base-10 integer,n , convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive 1's in n's binary representation.



  1. import math
  2. import os
  3. import random
  4. import re
  5. import sys
  6. if __name__ == '__main__':
  7. n = int(input())
  8. numbers = str(bin(n)[2:]).split('0')
  9. lenghts = [len(num) for num in numbers]
  10. print(max(lenghts))
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube