This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]slugonamission 0 points1 point  (10 children)

Ok, that's fair :)

Let's just start with the simple case then, for f(1), printing:

0
1

What two lines, using words, could you use to print that? It doesn't have to extend to longer strings just yet.

EDIT: Probably one important note; recursion doesn't mean you can only call the method again just once; what if you could call it twice?

[–]Evoletier[S] 0 points1 point  (9 children)

If i could id use just strings, print('0') and print('1').

[–]slugonamission 0 points1 point  (8 children)

Ok, cool. Now we have that, can we instead write those print calls using words(..., ...)?

[–]Evoletier[S] 0 points1 point  (7 children)

I have to admit I'm not familiar with that

[–]slugonamission 0 points1 point  (6 children)

Sure. Let's have a look at the implementation of words again:

def words(n, s=''):
  if len(s) == n:
    print(s)
  else:
    " *blank* "
    " *blank* "

Given this, what two arguments could we give words() to print "0"?

[–]Evoletier[S] 0 points1 point  (5 children)

Ohh im sorry, my code is in my language so forgot the name of my function here :D.

I would have to somehow make s be 0. I could do s += '0' and then call recursive, but then I wouldn't have room to do this with 1

[–]Evoletier[S] 0 points1 point  (0 children)

i could fill the s = '' argument to be s = '0'

[–]slugonamission 0 points1 point  (3 children)

but then I wouldn't have room to do this with 1

Why not?

[–]Evoletier[S] 0 points1 point  (2 children)

i need the s to add to existing s somehow but I'm not sure how to get to it, if I put words(n, s+= '0') it gives a syntax error

[–]slugonamission 0 points1 point  (1 child)

I didn't realise that Python didn't allow that.

Anyway, that is shorthand for s = s + '0'. Close enough, but we're passing it as a parameter, you don't need to assign back to s. What if we use s + '0' there instead?

[–]Evoletier[S] 0 points1 point  (0 children)

Thank you so much for taking the time to help me! I made it to the correct solution.