I tried looking at other threads but still couldn't figure it out.
I am using this code:
numbers = [5,1,5,2,4]
for i in numbers:
for x in range(0,i):
print "*",
print""
It prints:
* * * * *
*
* * * * *
* *
* * * *
etc.
I would like it to print:
* *
* * *
* * *
* * * *
* * * * *
I understand i must use if statements for whitespace or *
Any help is appreciated
numbers = [5,1,5,2,4]
for h in range(max(numbers), 0, -1):
for x in numbers:
if x >= h:
print '*',
else:
print ' ',
print ""
or a shorter version.
for h in range(max(numbers), 0, -1):
print ' '.join('*' if x >= h else ' ' for x in numbers)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With