elena1234

How to print matrix ( in Python)

Jan 21st, 2022 (edited)
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. picture = [
  2.     [0,0,0,1,0,0,0],
  3.     [0,0,1,1,1,0,0],
  4.     [0,1,1,1,1,1,0],
  5.     [1,1,1,1,1,1,1],
  6.     [0,0,0,1,0,0,0],
  7.     [0,0,0,1,0,0,0]
  8. ]
  9.  
  10. for row in range(len(picture)):
  11.     for col in range(len(picture[row])):
  12.         if(picture[row][col] == 1):
  13.          print('*', end = '')
  14.         else:
  15.          print(' ', end = '')
  16.     print()
  17.    
  18.  
  19. # Another way
  20. print()
  21.  
  22. for line in picture:
  23.     for pixel in line:
  24.         if(pixel == 1):
  25.          print('*', end = '')
  26.         else:
  27.          print(' ', end = '')
  28.     print()
  29.  
Add Comment
Please, Sign In to add comment