Formated print

PYTHON programe is:

#
#   Formated print
#
X = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Y = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
a = 7
b = 15
print(" a= %5d b= %5d" %(a, b))
nr = len(X)
i = 0 
while i < nr:
    print("%5d" %(X[i]))
    i = i +1
print('List was printed ', ' ')
row_number = len(Y)
column_number = len(Y[0])
i = 0 
while i < row_number:
    j = 0 
    while j < column_number:
        print("%5d " %(Y[i][j]), end =" ")
        j = j+1
    print(" " )
    i = i +1
print('List of list (matrix) was printed ', ' ') 

Results are:

Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
============== RESTART: /Users/ionivan/Documents/FormatedPrint.py ==============
 a=     7 b=    15
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
List was printed   
    1      2      3   
    4      5      6   
    7      8      9   
List of list (matrix) was printed 

(March 27, 2022)

Comments

Popular posts from this blog

Pointers in PYTHON?

Generates M prime numbers