0
how to print *** ** * ** ***
10 Antworten
+ 1
the way the output looks like depends on the font used. An editor for coding and a console to display text output use monospaced fonts and will show the stars right aligned. This Q&A uses a proportional font where the width of a space is less than the width of a star, so the output looks like an hourglass:
***
**
*
**
***
0
for i in range(5):
print (' '*(2-abs(2-i)),'*'*(abs(i-2)+1))
0
carberlaf can u plzzz elaborate?
0
thankew so much Ralf
0
thankew so much carberlaf
0
Ralf can u plzz elaborate?plzzz
0
carberlaf i got u..ty
0
i is assigned 0, 1, 2, 3, 4
Funktion abs() returns the positive value of its argument, so
abs(2-i) or abs(i-2) return 2, 1, 0, 1, 2 (both!)
printed are then spaces: 0, 1, 2, 1, 0 and stars: 3, 2, 1, 2, 3
0
Firstly, in your question the chars are aligned "between" the chars in the previus line.
I don't know how it's made. The chars are always aligned in columns.
for x in reversed(range(1,4)): # x takes the values 3,2,1 because the function reversed.
print('*' * x) # string '*' repeat x times.
for x in range(2,4): # I've modified this line from range(1,4) because the repetition of string "*"
print('*' * x)
You can also: print(''' # three '
***
**
*
**
***
''') # another three '
0
Ok to you, Ralf. Thanks.