w3codeworld logo
  • Home
  • C
  • C++
  • Java
  • Python3
  • JavaScript
  • C#
  • PHP
  • Codeigniter
  • Laravel
  • Articles
  1. Home
  2. Articles
  3. Write a program of spiral pattern printing in python language
  • PHP
  • Codeigniter
  • Laravel
  • C
  • C++
  • Java
  • Python3
  • JavaScript
  • C#

Write a program of spiral pattern printing in python language

  • Author: Admin
  • Last Updated: 2020-12-25
  • Category: Python3

Write a program of spiral pattern printing in python language. There are you will learn how to print the spiral pattern of a matrix.

 

Take an example to print the spiral pattern through a python program:

# Write a program of a spiral pattern
# printing in python language

def spiralPrint(m, n, arru):
    # m is the rows
    # n is the columns
    # arru is the list of elements
    k, l = 0, 0

    while k < m and l < n:
        pass
        # This will print the first row from the remaining rows
        for i in range (l, n):
            print (arru[k][i], end=", ")

        k += 1

        # This will print the last column from the remaining columns
        for i in range (k, m):
            print (arru[i][n - 1], end=", ")

        n -= 1

        # This will print the last row from the remaining rows
        if k < m:
            for i in range (n - 1, l - 1, -1):
                print (arru[m - 1][i], end=", ")

            m -= 1

        # This will print the first column from the remaining columns
        if l < n:
            for i in range (m - 1, k - 1, -1):
                print (arru[i][l], end=", ")

            l += 1

    print (end="\n")

arru = [
    [31, 32, 33, 34, 35, 36],
    [47, 48, 49, 40, 41, 42],
    [53, 54, 55, 56, 57, 58]
]

print ("-----The spiral pattern is-----")
# This will print the spiral pattern
spiralPrint(3, 6, arru)

 

Output:

-----The spiral pattern is-----
31, 32, 33, 34, 35, 36, 42, 58, 57, 56, 55, 54, 53, 47, 48, 49, 40, 41,

 

Tags:

# python program of a spiral matrix from center

# python program to generate a spiral matrix

# python program of reverse spiral matrix

# python program of a print matrix in a waveform

 

Related Articles

Write a python program to convert an array into zig-zag fashion using the function Write a python program to print a hollow square star pattern with diagonal using loops (for and while loop) How to print a star pattern without using loop in the python programming language Write a python program to find the sum of a zig-zag pattern in a given matrix using the recursion Write a program to make transformation matrix rotation 90 degrees clockwise in python language Write a program of spiral pattern printing in python language How to find the sum of each row and column of a matrix in python language Write a program to print the left & right arrow pattern in python language Write a program to draw the half pyramid pattern in python language of stars using the for loop How to print the rhombus pattern in the python language of the stars using the for loop Write a python program to print the butterfly pattern of the numbers by using the for loop How to print the hollow diamond pattern in python language Python program to print diamond pattern of stars by using the for loop Write a python program to draw a rectangle using for loop Write a program to print the pascal triangle pattern in python language Write a program to print Floyd's triangle number pattern in python language Write a program to print the matrix pattern in python language using the for loop Python program to check leap year using the if-else and by using the switch case statement Python program to find the roots of a quadratic equation using the sqrt() function with the if-else condition Python program to find GCD of two numbers using the while loop and using the for loop Python program to find LCM of two numbers using for loop and with GCD calculation Python program to calculate the power of N number using for loop and by using pow function Python program to find the Normal & Trace of a square matrix by using the for loop Python program to multiply two same dimension matrices by using the for loop Python program to find the SUM of the N input numbers using arrays with for loop Python program to find the largest and smallest element in an array by using for loop Python program to print the multiplication table of any integer number with multiplication range Python program to print prime numbers from 1 to N using for loop Python program to check input number is even or odd using if-else statement and with conditional operator Python program to find the average of N numbers by using for loop Python program to reverse a string by using the for loop Python program to find sum of digits of a number using while loop of any integer number Python program to check palindrome number using while loop or not using function of any number Python program to generate the fibonacci series using iteration of the for loop Python program to find the factorial of a number using for loop Python program to check the input character is a vowel or consonant character Python program to implement & use a switch case statement to make decisions Python program of decision making by using if & if-else statement Python program to find the ASCII value of a character Python program to take inputs from the user Python program to enter the P, T, R, and calculate its Compound Interest Python program to enter the P, T, R, and calculate its Simple Interest Python program to enter the marks of five subjects and calculate total, average, and percentage Python program to calculate the area of an equilateral triangle Python program to enter the base and height of a triangle and find its area Python program to enter the two angles of a triangle and find the third angle Python program to enter any number and calculate its square root Python program to find the power of any number x^y Python program to convert the days into years, weeks, and days Python program to enter the temperature in Fahrenheit and convert it to Celsius
Recent Articles
  • Write a program to find all the patterns of 0(1+)0 in the given string
  • C# program to enter two numbers and find their sum
  • Write a c++ program to store information of a student using the structure with the for loop
  • Write a c program to store information of a student using the structure with the for loop
  • How to write a c++ program to find the sum of natural numbers using recursion
  • How to write a c program to find the sum of natural numbers using recursion
  • Write a python program to convert an array into zig-zag fashion using the function
  • C program to perform input/output of all basic data types
  • Write a python program to print a hollow square star pattern with diagonal using loops (for and while loop)
  • Write a c program to make a circular rotation of an array by k positions using the loops
View All Articles
  W3Codeworld

Get the latest updates

  • ABOUT US
  • About Company
  • Contact Us
  • Terms Conditions
  • Privacy Policy
  • Top Tutorials
  • PHP
  • Codeigniter
  • Laravel
  • Top Articles
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • PHP

© Copyright 2020-2021. All Rights Reserved.