lundi 6 février 2017

Cant add number from one list to another

What I did was I chose a random number in the cerealBoxes list, then removed it from the list. I'm trying to take the number that I removed from cerealBoxes and put it into the list "BoxesPicked". When I append it to the other array I get a error.

Code:

import random

cerealBoxes = [1,2,3,4,5,6]
boxesPicked = []

def pickBox():
        pickCerealBox = random.choice(cerealBoxes)
        print(pickCerealBox)

        cerealBoxes.remove(pickCerealBox)
        print(cerealBoxes)

        print(pickCerealBox)
        pickCerealBox.append(boxesPicked)


pickBox()

When you run the program:

4
[1, 2, 3, 5, 6]
Traceback (most recent call last):
4
  File "C:/Users//Random Number/Simulation/cerealPrize.py", line 18, in <module>
    pickBox()
  File "C:/Users//Random Number/Simulation/cerealPrize.py", line 15, in pickBox
    pickCerealBox.append(boxesPicked)
AttributeError: 'int' object has no attribute 'append'

Process finished with exit code 1




Aucun commentaire:

Enregistrer un commentaire