how to print *** ** * ** *** | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to print *** ** * ** ***

16th Sep 2016, 4:03 PM
Arshee Siddiqui
Arshee Siddiqui - avatar
10 Answers
+ 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: *** ** * ** ***
18th Sep 2016, 8:36 AM
Ralf
0
for i in range(5): print (' '*(2-abs(2-i)),'*'*(abs(i-2)+1))
16th Sep 2016, 6:35 PM
Ralf
0
carberlaf can u plzzz elaborate?
16th Sep 2016, 7:11 PM
Arshee Siddiqui
Arshee Siddiqui - avatar
0
thankew so much Ralf
16th Sep 2016, 7:12 PM
Arshee Siddiqui
Arshee Siddiqui - avatar
0
thankew so much carberlaf
16th Sep 2016, 7:12 PM
Arshee Siddiqui
Arshee Siddiqui - avatar
0
Ralf can u plzz elaborate?plzzz
16th Sep 2016, 7:12 PM
Arshee Siddiqui
Arshee Siddiqui - avatar
0
carberlaf i got u..ty
16th Sep 2016, 7:12 PM
Arshee Siddiqui
Arshee Siddiqui - avatar
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
16th Sep 2016, 10:43 PM
Ralf
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 '
17th Sep 2016, 6:30 AM
carberlaf
0
Ok to you, Ralf. Thanks.
18th Sep 2016, 9:10 AM
carberlaf