Upside Down Pyramid (py)
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 height
Solution 1:
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))
Post a Comment for "Upside Down Pyramid (py)"