Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. # python3.5 labb2_3.py
  2. # coding=utf-8
  3. print("Borjan av programmet")
  4.  
  5. def enterthematrix(filename):
  6. with open(filename, "r") as data:
  7. data=data.readlines()
  8.  
  9. data=[i.strip() and i.split() for i in data]
  10.  
  11. return(data)
  12.  
  13. matrix=enterthematrix("Hmatris.txt")
  14.  
  15. bokstav='X'
  16. width = len(matrix)
  17. height = len(matrix[0])
  18.  
  19. for i in range(0,height):
  20. print(matrix[i])
  21.  
  22. def kollSimon():
  23. result = 0
  24. for i in range(0,height):
  25. for j in range(0,width):
  26. if matrix[i][j] == bokstav:
  27. result = result + 1
  28. if result == 5:
  29. print("Row with X = " + str(i + 1))
  30. result = 0
  31.  
  32. for i in range(0,width):
  33. for j in range(0,height):
  34. if matrix[j][i] == bokstav:
  35. result = result + 1
  36. if result == 5:
  37. print("Column with X = " + str(i + 1))
  38. result = 0
  39.  
  40. if width == height:
  41. for i in range(0,width):
  42. if matrix[i][i] == bokstav:
  43. result = result + 1
  44. if result == 5:
  45. print("Diagonal with X = top left to bottom right")
  46. result = 0
  47.  
  48. for i in range(0,width):
  49. if matrix[width-1-i][i] == bokstav:
  50. result = result + 1
  51. if result == 5:
  52. print("Diagonal with X = top right to bottom left")
  53. result = 0
  54. return
  55.  
  56. fannsfem = kollSimon()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement