If n equals zero, it prints an empty string (which only appears like an empty line).
We have discussed a similar function that returns the list (let's call that function get_binary_strings) of all binary strings of length n.
You can utilize that function here:
Implement that get_binary_strings function.
Call get_binary_strings from print_binary_strings which prints the list returned by the former.
However, this function, print_binary_strings, does not want us to return such a list. It only wants us to print all the binary strings of length n. This relaxed requirement may result in a more straightforward (but tricky) recursion code for the function.
You'll like the "domino effect" once you attain it.
Can you then modify the code slightly to also print all the binary strings of lengths 0 to n? For example, with this little change, the program should produce the following output:
Here is a sample output:
If
n
equals zero, it prints an empty string (which only appears like an empty line).We have discussed a similar function that returns the list (let's call that function
get_binary_strings
) of all binary strings of lengthn
.You can utilize that function here:
get_binary_strings
function.get_binary_strings
fromprint_binary_strings
which prints the list returned by the former.However, this function,
print_binary_strings
, does not want us to return such a list. It only wants us to print all the binary strings of lengthn
. This relaxed requirement may result in a more straightforward (but tricky) recursion code for the function.You'll like the "domino effect" once you attain it.
Can you then modify the code slightly to also print all the binary strings of lengths
0
ton
? For example, with this little change, the program should produce the following output: