vendredi 22 octobre 2021

How do I identify if a variable is in a list?

How do I identify if a randomly selected variable is in a list? Python 3

Example:

WarriorList = ['Achilles', 'Sun Wukong']
GuardianList = ['Ares', 'Ymir']
HunterList = ['Apollo', Artemis']
MageList = ['Anubis', 'ra']

Tank = ()

def TankPick():
    Tank = (random.choice(WarriorList))
    print (Tank)

def BalancePick():
    if (Tank) in WarriorList:
        print ('yes')
        print (random.choice(Magelist))
    else:
        print ('no')
        print (random.choice(Hunterlist))

Expected outcome:

'Sun Wukong'
'yes'
'ra'

or

'Ymir'
'no'
'Artemis'



Aucun commentaire:

Enregistrer un commentaire