我使用Python 2.7编写了一个模块memories.py(遗憾的是,由于某些限制,我无法使用最新版本)。它看起来如下。
import random
def get_a_random_memory(length, upper_sum_range, lower_sum_range):
# Start with a blank memory
memory = list()
# For each bit along the length we add a random value
for i in range(0, length):
memory.append((2 * random.randint(0, 1) - 1))
return memory
错误信息如下。
>>> import memories
>>> print memories.get_a_random_memory(5, 0, 10)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "xyz\memories.py", line 21, in get_a_random_memory
# For each bit along the length we add a random value
NameError: global name 'randint' is not defined
有人可以帮助我吗?