# Buggy code
def declare(self, name, memory_type, memory_size=1, shared_region=None, offsets=None):
    """DECLARE a quil variable

    This adds the declaration to the current program and returns a MemoryReference to the
    base (offset = 0) of the declared memory.

    .. note::
        This function returns a MemoryReference and cannot be chained like some
        of the other Program methods. Consider using ``inst(DECLARE(...))`` if you
        would like to chain methods, but please be aware that you must create your
        own MemoryReferences later on.

    :param name: Name of the declared variable
    :param memory_type: Type of the declared variable
    :param memory_size: Number of array elements in the declared memory.
    :param shared_region: You can declare a variable that shares its underlying memory
        with another region. This allows aliasing. For example, you can interpret an array
        of measured bits as an integer.
    :param offsets: If you are using ``shared_region``, this allows you to share only
        a part of the parent region. The offset is given by an array type and the number
        of elements of that type. For example,
        ``DECLARE target-bit BIT SHARING real-region OFFSET 1 REAL 4 BIT`` will let you use
        target-bit to poke into the fourth bit of the second real from the leading edge of
        real-region.
    :return: a MemoryReference to the start of the declared memory region, ie a memory
        reference to ``name[0]``.
    """
    self.inst(
        Declare(
            name=name,
            memory_type=memory_type,
            memory_size=memory_size,
            shared_region=shared_region,
            offsets=offsets,
        )
    )
    return MemoryReference(name=name, declared_size=memory_size)


# Traceback (ValueError)
`ValueError: if c is a list/tuple, its first member should be a string

Please enter number of sides: 60

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-30-d058bffa3dca> in <module>()
65     number_of_sides = int(input("Please enter number of sides: "))
66     while True:
---> 67         print(roll_die(number_of_sides))

<ipython-input-30-d058bffa3dca> in roll_die(n)
52     addresses = list(range(qubits_needed(n)))
53     if not n in dice:
---> 54         dice[n] = die_program(n)
55     die = dice[n]
56     # Generate results and do rejection sampling.

<ipython-input-30-d058bffa3dca> in die_program(n)
31     # Measure everything.
32     for q in range(qubits):
---> 33         prog.measure(q, [q])
34     return prog
35

~/anaconda3/lib/python3.6/site-packages/pyquil/quil.py in measure(self, qubit_index, classical_reg)
284         :rtype: Program
285         """
--> 286         return self.inst(MEASURE(qubit_index, classical_reg))
287
288     def reset(self, qubit_index=None):

~/anaconda3/lib/python3.6/site-packages/pyquil/gates.py in MEASURE(qubit, classical_reg)
489         address = MemoryReference("ro", classical_reg)
490     else:
--> 491         address = unpack_classical_reg(classical_reg)
492     return Measurement(qubit, address)
493

~/anaconda3/lib/python3.6/site-packages/pyquil/quilatom.py in unpack_classical_reg(c)
137             c = (c[0], 0)
138         if not isinstance(c[0], str):
--> 139             raise ValueError("if c is a list/tuple, its first member should be a string")
140         if not isinstance(c[1], int):
141             raise ValueError("if c is a list/tuple, its second member should be an int")

ValueError: if c is a list/tuple, its first member should be a string `

# Fixed code
def declare(
    self, name, memory_type="BIT", memory_size=1, shared_region=None, offsets=None
):
    """DECLARE a quil variable

    This adds the declaration to the current program and returns a MemoryReference to the
    base (offset = 0) of the declared memory.

    .. note::
        This function returns a MemoryReference and cannot be chained like some
        of the other Program methods. Consider using ``inst(DECLARE(...))`` if you
        would like to chain methods, but please be aware that you must create your
        own MemoryReferences later on.

    :param name: Name of the declared variable
    :param memory_type: Type of the declared variable
    :param memory_size: Number of array elements in the declared memory.
    :param shared_region: You can declare a variable that shares its underlying memory
        with another region. This allows aliasing. For example, you can interpret an array
        of measured bits as an integer.
    :param offsets: If you are using ``shared_region``, this allows you to share only
        a part of the parent region. The offset is given by an array type and the number
        of elements of that type. For example,
        ``DECLARE target-bit BIT SHARING real-region OFFSET 1 REAL 4 BIT`` will let you use
        target-bit to poke into the fourth bit of the second real from the leading edge of
        real-region.
    :return: a MemoryReference to the start of the declared memory region, ie a memory
        reference to ``name[0]``.
    """
    self.inst(
        Declare(
            name=name,
            memory_type=memory_type,
            memory_size=memory_size,
            shared_region=shared_region,
            offsets=offsets,
        )
    )
    return MemoryReference(name=name, declared_size=memory_size)