Adding a new line character to a variable in python
本问题已经有最佳答案,请猛点这里访问。
我有下面的函数来获得下面的输出
1 2 3 | 22 4444 666666 |
相反,我正在
1 2 3 4 5 | '22 4444 666666 88888888 ' |
你知道我哪里出错了吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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)+" " ...: else: ...: n = n - 1 ...: for i in range(2,n+1,2): ...: solution += (str(i)*i)+" " ...: return solution |
4444
666666
88888888
'
1 | print EvenLadder(6) |