组元素顺序,'NoneType'对象没有属性'value'

Order of group element, 'NoneType' object has no attribute 'value'

我正在尝试编写一个函数来查找组中元素的顺序。我不断收到此消息

'NoneType' object has no attribute 'value'.

这是我的代码:

def order_group_element(G, x):
    if not ((IsSymmetricGroup(G) or IsCyclicGroup(G)) and x in G):
       raise ValueError
   identity = G.identity()
   if x == identity:
       return 1
   a = 2
   i = x
   while not i == identity:
       i = G[i]
       a = a + 1
   return a 

我的输入类似于以下内容:

a = CyclicGroup(500)
print 'G[1] Order = ',order_group_element(a, a[1])

我在我的函数中从这一行得到错误:

while not i == identity:

我已经通过更改解决了这个问题

i = G[i] 

i = i * x 

在 while 循环中,由于乘法已经在 groups 包中定义,这是我不知道的。

感谢您的帮助。