Converting for loops to while loops in python

后端 未结 3 1510
既然无缘
既然无缘 2020-12-11 08:55

I am struggling to find an efficient way to convert these for loops to a working set of while loops. Any Suggestions? I am using 2.7

def pr         


        
3条回答
  •  借酒劲吻你
    2020-12-11 09:39

    You can get rid of the inner loop with string multiplication operator (*) :

    def printTTriangle(height):
     j = 1
     while j <= height:
         print 'T' * j + '\n '
         j += 1
    

提交回复
热议问题