Evil Number | returns number of 1 s from the binary number ; Counting 1 s ; Check if number is evil or not ; Converting n to binary form ; Calculating Remainder Storing the remainders in binary form as a number ; Calling the count_one function to count and return number of 1 s in bin ; Driver Code
def count_one ( n ) : NEW_LINE INDENT c_one = 0 NEW_LINE while n != 0 : NEW_LINE INDENT rem = n % 10 NEW_LINE if rem == 1 : NEW_LINE INDENT c_one = c_one + 1 NEW_LINE DEDENT n = n / 10 NEW_LINE DEDENT return c_one NEW_LINE DEDENT def checkEvil ( n ) : NEW_LINE INDENT i = 0 NEW_LINE binary = 0 NEW_LINE while n != 0 : NEW_LINE INDENT r = n % 2 NEW_LINE binary = binary + r * ( int ( 10 ** i ) ) NEW_LINE n = n / 2 NEW_LINE DEDENT n_one = count_one ( binary ) NEW_LINE if n_one % 2 == 0 : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT num = 32 NEW_LINE check = checkEvil ( num ) NEW_LINE if check : NEW_LINE INDENT print num , " is ▁ Evil ▁ Number " NEW_LINE DEDENT else : NEW_LINE INDENT print num , " is ▁ Odious ▁ Number " NEW_LINE DEDENT