0

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()
hauntboy
  • 15
  • 5

1 Answers1

0

You should Try

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

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

    else:
        print("Valor has fainted")

battle()