Problem Statement
Print an arrow star pattern for a given number of rows N. Note: N is always odd, and there is a space after every star.
Input Format
Integer N
Output Format
The arrow pattern in N lines
Examples
Sample Input 1 :
7
Sample Output 1 :
*
* *
* * *
* * * *
* * *
* *
*
Sample Input 2 :
11
Sample Output 2 :
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Solution Approach
Steps to solve:
- Read the number of rows
N. - Split the problem into two halves: - Upper half including the middle row - Lower half (reverse of upper half without the middle row)
- Print spaces followed by stars with one space after each star.
- Ensure symmetry for correct arrow shape.
Python Code
N = int(input())
n1 = (N + 1) // 2
n2 = N - n1
# Upper half
i = 1
while i <= n1:
print(' ' * (i - 1) + '* ' * i)
i += 1
# Lower half
i = 1
while i <= n2:
print(' ' * (n2 - i) + '* ' * (n2 - i + 1))
i += 1
Tags:
Solutions
