Simplifying Reverse Triangle Code (While Loop)

后端 未结 1 1086
迷失自我
迷失自我 2021-01-25 00:01

I have successfully created a code to print a horizontally flipped triangle using a while loop. Now although it works, I was wondering if i could simplify this i.e. without usin

相关标签:
1条回答
  • 2021-01-25 00:44

    Essentially, you still need to keep track of which row you're on and just do a little more math to see how many *'s and " "'s there should be. Hope this helps.

    myLen = 5
    i = 1
    while myLen >= i:
        print( ("*" * i).rjust(myLen) )
        i += 1
    
    0 讨论(0)
提交回复
热议问题