Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. # First Exercise
  2.  
  3. def change(source,x,y):
  4. # @param source: Picture
  5. # @param x and y: int
  6.  
  7. if getWidth(source) != getHeight(source) or x < 0 or y < 0 or x >= getWidth(source) or y >= getHeight(source):
  8. repaint(source)
  9.  
  10. else:
  11.  
  12. for i in range(getWidth(source)):
  13. pixel = getPixel(source,i,y)
  14. pixelSec = getPixel(source,x,i)
  15. setColor(pixelSec,getColor(pixel))
  16. setColor(pixel,getColor(pixelSec))
  17. repaint (source)
  18.  
  19. # Second Exercise
  20.  
  21. def change_matrix(matrix, x, y):
  22. # @param matrix: matrix
  23. # @param x and y: int
  24. # return matrix
  25.  
  26. if x < 0 or y < 0 or x > len(matrix)-1 or y > len(matrix[c])-1:
  27. return matrix
  28.  
  29. for count in range(len(matrix)):
  30. if len(matrix[count]) != len(matrix):
  31. return matrix
  32.  
  33. else:
  34.  
  35. for i in range(len(matrix[x])):
  36. row = matrix[x][i]
  37. matrix[x][i] = matrix[i][y]
  38. matrix[i][y] = row
  39. return matrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement