Pattern Printing 9 Python HackerRank Answer

 Given a number N, print a pattern as shown below :

n = 1
*

n = 2
 *
***
 *

 n = 3
   *
  ***
 *****
  ***
   *
and so on..

Hint : Print the upper triangle and the lower reverse triangle separately.

Input Format

Only one integer, the number n.

Constraints

1 <= n <= 100

Output Format

The required pattern

Sample Input 0

1

Sample Output 0

*
Source Code
# Enter your code here. Read input from STDIN. Print output to STDOUT
n=int(input())
for i in range(1,  n + 1):
    print(' ' * (n - i) + '*' *(2 * i - 1))
for i in range(1,n):
    print(' ' * i + '*' * (2 *(n - i) - 1))

Comments