Upside Down Pyramid (PY)

前端 未结 1 505
不知归路
不知归路 2020-12-12 06:55

So I have an assignment that requires me to print an upside down pyramid made out of asterisks in Python. I know how to print out a normal pyramid but how do I flip it? The

相关标签:
1条回答
  • 2020-12-12 07:22

    If you want to reverse the pyramid, just reverse the outer loop. Thanks to the magic of python, you can just use the reversed builtin function. Also, you can simplify the body of the loop a little bit using string multiplication and the str.center function.

    for i in reversed(range(p)):
        print(('*' * (1+2*i)).center(1+2*p))
    
    0 讨论(0)
提交回复
热议问题