Python Program to Generate Flag of Nepal

In this python example, we first read number of row from user using built-in function input(). Since function input() returns string value, we need to convert given number to number type using int(). And then we generate Falg of Nepal pattern using stars.

Note: Here row number indicates number of row in each section in pattern. If we give input row number 7 then total row will be 21 :)

Python Program to Generate Flag of Nepal


# Python Program to Generate Flag of Nepal

# Generating Triangle Shape
def triangleShape(n):
    for i in range(n):
        for k in range(i+1):
            print('*',end=' ')
        print()

# Generating Pole Shape
def poleShape(n):
    for i in range(n):
        print('*')

# Input and Function Call
row = int(input('Enter number of rows: '))
triangleShape(row)
triangleShape(row)
poleShape(row)

In this program print() only is used to bring control to new lines.

Output

Enter number of rows: 7

* 
* * 
* * * 
* * * * 
* * * * * 
* * * * * * 
* * * * * * * 
* 
* * 
* * * 
* * * * 
* * * * * 
* * * * * * 
* * * * * * * 
*
*
*
*
*
*
*