mercredi 6 novembre 2019

Using random.choice() in Python3

I am getting an error when I try to assign a random vertex from 3 possible vertices to a variable c.

#Establish locations for the 3 vertices
vertex1 = (0,0)
vertex2 = (canv_width,0)
vertex3 = (canv_width//2,canv_height)
c = random.choice(vertex1,vertex2,vertex3)

Error:

TypeError: choice() takes 2 positional arguments but 4 were given

Online someone said to try and wrap the sequence of choices in a list. So i tried:

c = random.choice[vertex1,vertex2,vertex2]

error:

TypeError: 'method' object is not subscriptable

Any ideas?




Aucun commentaire:

Enregistrer un commentaire