mardi 18 août 2015

Gettin error message 'NameError: global name 'randint' is not defined'

I have written a module memories.py using Python 2.7 (unfortunately, I cannot use the latest version due to some restriction). It looks as follows.

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

The error message is as follows.

>>> 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

Could anyone please help me out here?




Aucun commentaire:

Enregistrer un commentaire