samedi 9 mars 2019

Using list in Python

I want to display the variable name and not its value when random function generates any output from the list i have created. When i asign the value to A

A=10       
MyList=['A',1,2,3] 

a1=random.choice(MyList)    
print a1                               #i want 'A' printed here

a2=random.choice(MyList)

print a2                   #if 2 is taken on random

a=a1+a2                    #while adding it should to 10+2 

As i execute it, the output of a1 comes 10 and not 'A'. if i make it string it won't add with the number in a2




Aucun commentaire:

Enregistrer un commentaire