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
Jayaram
  • 6,276
  • 12
  • 42
  • 78

1 Answers1

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)
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115