vendredi 15 juillet 2016

How to randomly choose a string from a list, and insert it into a new one? [on hold]

I've recently made this program to simulate the concept of random generation with my example being trees, however I don't understand why I can't find an element within the list with a randomly generated number. I tried Leaves.index() but It doesn't seem to be working. Are there any ways to randomly take a string from one of my lists and add it into another list?

import random

Leaves=["Pointy","Rounded","Maple","Pine","Sticks"]
Trunk=["Oak","Birch","Maple","Ash","Beech","Spruce"]
Size=["Extra Large","Large","Medium","Small","Tiny"]
Tree=[]
while len(Tree)<len(Leaves)*len(Trunk)*len(Size):
    NewCombination=Leaves.index(random.randrange(len(Leaves)))+Trunk.index(random.randrange(len(Trunk)))+Size.index(random.randrange(len(Size)))
if Tree != NewCombination:
    Tree=Tree+NewCombination
print(Tree)

Error:

Traceback (most recent call last): File "C:/Users/invis_000/Documents/Coding/Python/Generation.py", line 8, in <module>




Aucun commentaire:

Enregistrer un commentaire