Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

form a chakravyuh matrix python

num=int(input("enter the length of square matrix"))
n_list=[[0 for x in range(num)] for y in range(num)]
n=1
low=0
high=num - 1
count=int((num+1)/2)

for i in range(count):
    for j in range(low,high+1):
        n_list[i][j]=n
        n+=1

    for j in range(low+1,high+1):
        n_list[j][high]=n
        n+=1

    for j in range(high-1,low-1,-1):
        n_list[high][j]=n
        n+=1

    for j in range(high-1,low,-1):
        n_list[j][low]=n
        n+=1

    low+=1
    high-=1



for i in range(num):
    for j in range(num):
        print(n_list[i][j],end="	")
    print()
Comment

PREVIOUS NEXT
Code Example
Python :: How to count a consecutive series of positive or negative values in a column in python 
Python :: python project pick text color according to background 
Python :: pyjone location 
Python :: skit learn decision 
Python :: first_last6 
Python :: napalm cli 
Python :: python cgi get raw post data 
Python :: get number of occurrences of substring case independent python 
Python :: ler arquivo xls no pandas 
Python :: arma-garch python 
Python :: Pte or Pvt 
Python :: ipywidgets unobserve functools partial 
Python :: convert math expression as string to int 
Python :: dict_leys to list 
Python :: save file in windows hidden folder python 
Python :: qq plot using seaborn with regression line 
Python :: python fibbonacci 
Python :: pandas continues update csv 
Python :: activate inherit function django 
Python :: csv.DictReader Skip Lines 
Python :: get element tag name beautfulsoup 
Python :: find average of list via for loop python 
Python :: effient way to find prime no inpython 
Python :: order dataframe by specific column c1 
Python :: convert a python object and store it in a JSON file in the local system 
Python :: group by month and year 
Python :: matplotlib get colorwheel 
Python :: load xgb 
Python :: how to find factorial number in python 
Python :: Handling errors while using os.makedirs() method 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =