 Tyler Deluc - 2 years ago 172
Python Question

Print asterisk arrow using only While loops in Python

I am trying to create an arrow out of asterisk's, where the amount of columns is entered by the user. Yes, I do know how to use for loops to accomplish this:

columns = int(input("How many columns? "))
while columns <= 0:
print ("Invalid entry, try again!")
columns = int(input("How many columns? "))
x = 1

for x in range(1, columns):
for x in range(x):
print(" ", end="")
print("*")

for x in range(columns,0,-1):
for x in range(x):
print(" ", end="")
print("*")

#output looks like

"""
How many columns? 3
*
*
*
*
*
"""

However my question is, how would I accomplish the same outcome using only while loops?

Thanks

Edit: I was going to post what I had thus far in trying to work it out myself, but it is now of no use!
Thank you all for your efficient varying answers! Much appreciated! Anmol Singh Jaggi

This should do:

columns = int(input("How many columns? "))

while columns <= 0:
print ("Invalid entry, try again!")
columns = int(input("How many columns? "))

x = 1
while x < columns:
y = 0
while y < x:
print(" ", end="")
y += 1
print("*")
x += 1

x = columns
while x > 0:
y = 0
while y < x:
print(" ", end="")
y += 1
print("*")
x -= 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download