lundi 8 février 2021

Using random.choice inside a list doesnt give me a new value unless I restart. (Python) [closed]

Inside my list of items (list_A), is an item that requires to be assigned another random value. However, when I run the code, I succesfully get a random item from list A, but when I get the "spell scroll" item, it always has the same spell attached to it, until you restart the code. I have tried a lot of things, using random.shuffle and global variables, but without success. This is my first time making a program, can someone please help me out?

This is the code:

import random
list_spells_0 = ['Virtue', 'Vicious Mockery', 'True Strike', 'Toll the Dead', 'Thunderclap', 'Thorn Whip']
list_A = ['Potion of healing'] * 50 + ["Spell scroll of " + random.choice(list_spells_0)] * 10
    
    
def item_A():
        x = random.choice(list_A)
        print(x)

def user_input():
    x = str(input())
    if x in ["A",  "a"]:
          item_A()
    user_input()

user_input()



Aucun commentaire:

Enregistrer un commentaire