Oct-07-2019, 08:32 AM
Hi,
I ask if there is someone could be explain this code that I found and why it was used this solution,because I didn't find nothing on Internet , only a fucntion called bin().
This program should be print the max rappresentation of binary number ,passed before in number with base 10 and then converted in binary number.
RavCoder
I ask if there is someone could be explain this code that I found and why it was used this solution,because I didn't find nothing on Internet , only a fucntion called bin().
This program should be print the max rappresentation of binary number ,passed before in number with base 10 and then converted in binary number.
5 n = int(input()) 6 max_one_count = 0 7 one_count = 0 8 9 while n != 0: 10 factor = n // 2 11 remainder = n - 2 * factor 12 n = factor 13 if remainder == 1: 14 one_count += 1 15 max_one_count = max(max_one_count, one_count) 16 else: 17 one_count = 0 18 19 print(max_one_count)Regards,
RavCoder