jeudi 12 décembre 2019

Randomly choosing variable out of a dictionary

I'm trying to have python choose a random variable out of my dictionary to run in the code but can't seem to get the correct syntax for it. If anyone can help that would be great.

def battle():
    moveset_dict = {
    "1": 25, 
    "2": 50,
    "3": 75,
    "4": 100,
    }
    hp = 100

    while hp > 0 :
        attack_chosen =  random.range(len(moveset_dict))
        hp = hp - attack_chosen
        print("Alar used", attack_chosen, "Valor has", hp, "hp")

    else:
        print("Valor has fainted")

battle()



Aucun commentaire:

Enregistrer un commentaire