Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # python3.5 labb2_3.py
- # coding=utf-8
- print("Borjan av programmet")
- def enterthematrix(filename):
- with open(filename, "r") as data:
- data=data.readlines()
- data=[i.strip() and i.split() for i in data]
- return(data)
- matrix=enterthematrix("Hmatris.txt")
- bokstav='X'
- width = len(matrix)
- height = len(matrix[0])
- for i in range(0,height):
- print(matrix[i])
- def kollSimon():
- result = 0
- for i in range(0,height):
- for j in range(0,width):
- if matrix[i][j] == bokstav:
- result = result + 1
- if result == 5:
- print("Row with X = " + str(i + 1))
- result = 0
- for i in range(0,width):
- for j in range(0,height):
- if matrix[j][i] == bokstav:
- result = result + 1
- if result == 5:
- print("Column with X = " + str(i + 1))
- result = 0
- if width == height:
- for i in range(0,width):
- if matrix[i][i] == bokstav:
- result = result + 1
- if result == 5:
- print("Diagonal with X = top left to bottom right")
- result = 0
- for i in range(0,width):
- if matrix[width-1-i][i] == bokstav:
- result = result + 1
- if result == 5:
- print("Diagonal with X = top right to bottom left")
- result = 0
- return
- fannsfem = kollSimon()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement