我想检查乘法表是否像以下不是代码,但我找不到另一种方式编写它的方法
* 0 1 2
0 |0 1 0
1 |0 0 0
2 |0 1 1
它在我的代码中存储为带有子列表的列表,例如
[[0,1,0], [0,0,0], [0,1,1]]
#How to write a function which checks elements satisfy the condition x*(y*z) = (x*y)*z ?
#This is what I have so far:
def is_associative(X):
n = len(X)
a = []
for i in range(n):
a.append[i]
for j in range(n):
a[j]*a[j] = X[j]
你应该遍历所有三个变量:
for x in range(n):
for y in range(n):
for z in range(n):
然后你需要检查是否
X[X[x, y], z] == X[x, X[y, z]]
对于所有值。