# Print all Strings of given length containing 0 or 1 using recursion

2818 views
8

Implement such a function print_01_strings(k,s,n) that, given a string s of length k, prints all the possible 0/1 strings that are completions of s to length n in the alphanumeric order. Naturally, when print_01_strings(0,'',n) is called, all the 0/1 strings of length n will be printed.

Use the following pattern to implement your solutions and feel free to use the solution sketch provided in the comments:

``````def print_01_strings(k, s, n):
#if k equal to n the function only needs to print s which is unique    completion
#otherwise, we'll print all the completions of the string s+'0' of length k+1
#and all the completions of the string s+'1' of length k+1

print_01_strings(0,'',int(input()))
``````

We're not going to do your homework for you. Make an honest effort at solving it, and if you're having trouble with some specific part of it, come back and let us know.

`itertools.combinations` can be really helpful in generating combinations... but make sure your you want combinations and not permuations or products

I already tried, it's not my fault that the teachers in London can't speak English

0

Best not to copy and paste your homework questions on here bruh

posted this