5

I have the below function to get the below output

22
4444
666666

Instead i'm getting

'22\n4444\n666666\n88888888\n'

Any ideas where im going wrong?

def EvenLadder(n):
    ...:     solution = ''
    ...:     if n <= 1:
    ...:         return solution
    ...:     elif n%2 ==0:
    ...:         for i in range(2,n+1,2):
    ...:             solution += (str(i)*i)+"\n"
    ...:     else:
    ...:         n = n - 1
    ...:         for i in range(2,n+1,2):    
    ...:             solution += (str(i)*i)+"\n"
    ...:     return solution
4
  • 1
    Try doing print(EvenLadder(n)) . You are just seeing the output of repr() , when you call the function without printing or storing the result in a variable . Give some value for n , obviously. Commented Jul 19, 2015 at 12:31
  • Your code works fine for me, The result is the same as you wished. Commented Jul 19, 2015 at 12:32
  • print EvenLadder(6).__repr__() - '22\n4444\n666666\n'; print EvenLadder(6) - 22 4444 666666 Commented Jul 19, 2015 at 12:33
  • Take a look at stackoverflow.com/q/1436703/4014959 and stackoverflow.com/q/7784148/4014959 Commented Jul 19, 2015 at 12:36

1 Answer 1

4

'22\n4444\n666666\n88888888\n' is the correct string representation of the expected result. In order to actually process the newline characters you need to print it:

print EvenLadder(6)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.