In the following code I used a while True:
loop and implemented break
, because I couldn't figure out a cleaner solution than an infinite loop. Is this approach considered bad practice? Here is my code:
while True:
z = int(input("Y: "))
if (z >= 0 and z <= 20):
break
for x in range(z):
print("-" * (z-x) + "*" * x + " " * x + "-" * (z-x))
... which outputs:
Y: 12
------------------------
-----------* -----------
----------** ----------
---------*** ---------
--------**** --------
-------***** -------
------****** ------
-----******* -----
----******** ----
---********* ---
--********** --
-*********** -