• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
November 03, 2022 |1.3K Views

Python Program to Print Square Star Pattern with diagonals

Description
Discussion

Python Program to print Square Star Pattern with diagonals

To print the character, we have to take an input that will denote the numbers the lines or size the pattern needs to be. We have to write conditions that make up the boundary pattern with diagonal and anti-diagonal.

Method 1: Conditional Approach

Taking an input from the user, we print ‘*’ inside the nested loop whenever the if condition is raised True depending upon the following different criteria.

1. Current row is first or nth  
2. Current column is first or nth
3. Diagonal where i == j
4. Anti-diagonal where j == n-i-1

Complexity of program

Space Complexity: O(1)
Time Complexity: O(n^2)