mercredi 17 juin 2015

How to obtain a random string from a list

My class was recently introduced to lists and our task is to randomly obtain a name from the said list, This is the code i have generated

import random
Random1 = random.randint(0,7)
Class_List = ['Noah','Simone','Ji Ho','Thanh','Nathanial','Soo','Mickel','Tuan','Thuy Linh']
print (ClassList[{}].format(Random1))

However i receive this error

Traceback (most recent call last):
  File "C:/Users/Mickel/Documents/Python/RPS Tournament/Rock Paper Sissor Tornament.py", line 4, in <module>
    print (ClassList[{}].format(Random1))
TypeError: list indices must be integers, not dict

Any solutions?




Aucun commentaire:

Enregistrer un commentaire