File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ def print_butterfly (n : int ) -> None :
2+ """
3+ Prints a butterfly pattern using the character '*' based on the input size.
4+
5+ The butterfly pattern has a symmetrical structure with an upper and lower half.
6+
7+ :param n: The size of the butterfly (side length).
8+ :return: None
9+
10+ Example:
11+ >>> print_butterfly(5)
12+ * *
13+ ** **
14+ *** ***
15+ **** ****
16+ *********
17+ **** ****
18+ *** ***
19+ ** **
20+ * *
21+ """
22+ # Upper half of the butterfly
23+ for i in range (1 , n + 1 ):
24+ print ("*" * i , end = "" )
25+ print (" " * (2 * (n - i )), end = "" )
26+ print ("*" * i )
27+
28+ # Lower half of the butterfly
29+ for i in range (n , 0 , - 1 ):
30+ print ("*" * i , end = "" )
31+ print (" " * (2 * (n - i )), end = "" )
32+ print ("*" * i )
33+
34+
35+ # Ask the user for input and print the butterfly
36+ n = int (input ("Enter the value of n: " ))
37+ print_butterfly (n )
You can’t perform that action at this time.
0 commit comments