Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

rangoli in python

def print_rangoli(size):
    width  = size*4-3
    string = ''

    for i in range(1,size+1):
        for j in range(0,i):
            string += chr(96+size-j)
            if len(string) < width :
                string += '-'
        for k in range(i-1,0,-1):    
            string += chr(97+size-k)
            if len(string) < width :
                string += '-'
        print(string.center(width,'-'))
        string = ''

    for i in range(size-1,0,-1):
        string = ''
        for j in range(0,i):
            string += chr(96+size-j)
            if len(string) < width :
                string += '-'
        for k in range(i-1,0,-1):
            string += chr(97+size-k)
            if len(string) < width :
                string += '-'
        print(string.center(width,'-'))
        

print_rangoli(10)


------------------j------------------
----------------j-i-j----------------
--------------j-i-h-i-j--------------
------------j-i-h-g-h-i-j------------
----------j-i-h-g-f-g-h-i-j----------
--------j-i-h-g-f-e-f-g-h-i-j--------
------j-i-h-g-f-e-d-e-f-g-h-i-j------
----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
--j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
j-i-h-g-f-e-d-c-b-a-b-c-d-e-f-g-h-i-j
--j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
------j-i-h-g-f-e-d-e-f-g-h-i-j------
--------j-i-h-g-f-e-f-g-h-i-j--------
----------j-i-h-g-f-g-h-i-j----------
------------j-i-h-g-h-i-j------------
--------------j-i-h-i-j--------------
----------------j-i-j----------------
------------------j------------------
Comment

PREVIOUS NEXT
Code Example
Python :: python if else variable assignment 
Python :: pyqt display math 
Python :: python watchgod 
Python :: python subtract one list from another 
Python :: pythondatetime cheatsheet 
Python :: python sftp put file 
Python :: add percentage column pandas 
Python :: python loop certain number of times 
Python :: window in python 
Python :: printing a range of no one line in python 
Python :: Static Assets in Django 
Python :: pandas groupby get all but first row 
Python :: python copy all files in a folder to nother folder 
Python :: pandas replace nan 
Python :: install python setuptools ubuntu 
Python :: df.shape 0 
Python :: how to get rid of all null values in array python 
Python :: max of a dict 
Python :: audacity 
Python :: researchpy correlation 
Python :: Install Basemap on Python 
Python :: dataframe split column 
Python :: pandas replace na with 0 
Python :: get all values of a dict python 
Python :: why men are better than woman 
Python :: tkinter app icon 
Python :: get path of notebook 
Python :: pandas add rows from df to another 
Python :: python pynput letter key pressed 
Python :: remove all zeros from list python 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =