-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL13Q2_SymmetricSquare.py
45 lines (38 loc) · 1.13 KB
/
L13Q2_SymmetricSquare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# A list is symmetric if the first row is the same as the first column,
# the second row is the same as the second column and so on. Write a
# procedure, symmetric, which takes a list as input, and returns the
# boolean True if the list is symmetric and False if it is not.
def symmetric(matrix):
if len(matrix) != len(matrix[0]):
return False
i = 0
while i < len(matrix):
j = 0
while j < len(matrix):
if matrix[i][j] != matrix [j][i]:
return False
j += 1
i += 1
return True
print symmetric([[1, 2, 3],
[2, 3, 4],
[3, 4, 1]])
#>>> True
print symmetric([["cat", "dog", "fish"],
["dog", "dog", "fish"],
["fish", "fish", "cat"]])
#>>> True
print symmetric([["cat", "dog", "fish"],
["dog", "dog", "dog"],
["fish","fish","cat"]])
#>>> False
print symmetric([[1, 2],
[2, 1]])
#>>> True
print symmetric([[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6]])
#>>> False
print symmetric([[1,2,3],
[2,3,1]])
#>>> False