Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to iteratively create a grid within a bigger grid in python

def grid_print(area, units):

   print_Area = (area * area)

   grid_rows = units + (units + 1) + 2

   grid_cols = units + 2

   if units % 2 == 0:           # If grid entry is even (it will end up making
        grid_rows += 1               # the square uneven, so increase number of rows by 1
                            # now grid is technically uneven
        for i in range(print_Area):
           for row in range(grid_rows):     # for each item in number of items(rows)
               for col in range(grid_cols): # for each item in number of items(columns)
                   if row == 0 or row == int(grid_rows/2) or row == grid_rows -1:    # if item is beginning, middle or end
                   # --  Formatting beam structure  -- #
                       if col == 0:                        # beginning, print '+' no '
'
                           print('+', end='')
                       elif col == grid_cols -1:                # end, print '+'
                       print('+')
                       elif int(grid_cols/2) == col:            # middle:
                           if grid_rows % 2 == 0:               # if grid is even, pad '+' with ' '
                               print(' + ', end='')        # if grid is uneven, no padding
                           else:                           # print '+' no '
'
                               print('+', end='')
                       elif col % 2 == 0:                  # if col item is an even number
                           print('-', end='')              # print '-' with no '
'
                       else:                               # else if col item is uneven item num
                           print(' ', end='')              # print ' ' no '
'
                   else:
                   # --  Formatting line structure  -- #
                       if col == 0:                        # if column is at starting position 0
                           print('|', end='')              # print '|' no '
'
                       elif col == int(grid_cols/2):            # if column is at middle pos
                           if units % 2 == 0:               # print '|' no '
'
                               print(' | ', end='')        # (has padding if grid is even or not)
                           else:
                               print('|', end='')
                       elif col == grid_cols -1:                # if column is at end position of grid
                           print("|")                      # print '|'
                       else:
                           print(' ', end='')              # all other circumstances, print ' ' no '
'
Comment

PREVIOUS NEXT
Code Example
Python :: masking function pyspark 
Python :: python program to find all prime numbers within a given range 
Python :: pandas forward fill after upsampling 
Python :: python seaborn violin plot fit data better 
Python :: python code for system of odes 
Python :: resource wordnet not found python 
Python :: pandas dataframe from multiple csv 
Python :: turn of axis 
Python :: python counter get most common 
Python :: skewness python 
Python :: an array of dates python 
Python :: how to create text file with python and store a dictionary 
Python :: how to type a dict in python 
Python :: python catch all exceptions 
Python :: tag for deleting from a list in python 
Python :: get wav file in dir 
Python :: flask import jsonify 
Python :: get text from table tag beautifulsoup 
Python :: python read text file 
Python :: python divide one column by another 
Python :: subprocess the system cannot find the file specified 
Python :: python numpy reverse an array 
Python :: open dicom images python 
Python :: python argparse 
Python :: perimeter of semicircle formula 
Python :: openpyxl delete rows 
Python :: python imread multiple images 
Python :: read bytes from file python 
Python :: how to install cuda in anaconda 
Python :: python requests get cookies 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =