lundi 3 mai 2021

Random dictionary pick?

I am pretty newbie to python, still learning. Here i faced a problem i can't figure out how to solve yet.

import random
materials = ["wood", "stone", "iron"]

wood = {
    "name": "wood",
    "weight": 50,
    "quality": 1
}

stone = {
    "name": "stone",
    "weight": 80,
    "quality": 2
}

iron = {
    "name": "iron",
    "weight": 110,
    "quality": 3
}

r = random.choice(materials)

Basically what i wanted to do is to print a specific dictionary depends from the r - random pick. Any tips on how to do that correctly?




Aucun commentaire:

Enregistrer un commentaire