Pyramids reduction - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Pyramids reduction (/thread-19199.html) |
Pyramids reduction - Technoob - Jun-17-2019 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. RE: Pyramids reduction - Yoriz - Jun-17-2019 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)
RE: Pyramids reduction - Technoob - Jun-17-2019 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() 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. RE: Pyramids reduction - Yoriz - Jun-17-2019 Ok either i misunderstood or you didn't describe very clearly what was required As you can create a single pyramid use a reversed range to alter base_size
|