Python Forum

Full Version: Pyramids reduction
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The problem is that I'm supposed to make a pyramid which reduces in size till reaching zero.

base_size=input("base_size:" )
base_size=int(base_size)
for r in range(base_size):
    for c in range(r+1):
        print('*',end='')
    print()
So far I can easily create one but I'm not sure how to make each version smaller than the last.
You can make a range count backwards
https://docs.python.org/3/library/stdtypes.html#range Wrote:class range(start, stop[, step])
for value in range(5, 0, -1):
       print(value)
Output:
5 4 3 2 1
This kind of worked. However,

base_size=input("base_size:" )
base_size=int(base_size)
for r in range(base_size,0,-1):
    for c in range(r+1):
        print('*',end='')
    print()
print()
Output:
base_size:6 ******* ****** ***** **** *** **
It turns it upside down. I need it to stay with the smallest number at the top and keep repeating this pattern till it gets to zero.

*
**
***
****
*****

*
**
***
****

*
**
***

*
**

Something like this.
Ok either i misunderstood or you didn't describe very clearly what was required Think

As you can create a single pyramid use a reversed range to alter base_size