Find the number of integers from 1 to n which contains digits 0 ' s ▁ and ▁ 1' s only | Function to find the number of integers from 1 to n which contains 0 ' s ▁ and ▁ 1' s only ; If number is greater than n ; otherwise add count this number and call two functions ; Driver code
def countNumbers ( x , n ) : NEW_LINE INDENT if x > n : NEW_LINE INDENT return 0 NEW_LINE DEDENT return ( 1 + countNumbers ( x * 10 , n ) + countNumbers ( x * 10 + 1 , n ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 120 ; NEW_LINE print ( countNumbers ( 1 , n ) ) ; NEW_LINE DEDENT