mardi 3 octobre 2017

Randomly generating integers to be used on a graph

the function of this program is to randomly generate numbers ranging from 1-10 for the variables right, left, up, down to be used on a 40 x40 graph. in order to have a list containing 2 numbers for the x and y variables, i have another random number generator that picks which will be chosen

import random
choice_x = random.randint(0, 1)
choice_y = random.randint(0, 1)
right = random.randint(10, 20)
left = random.randint(0, 10)
up = left = random.randint(0, 10)
down = left = random.randint(10, 20)
directions = [right, left, up, down]

if choice_x == 0:
  del directions[right]
elif choice_x == 1:
  del directions[left]

if choice_y == 0:
  del directions[up]
elif choice_y == 1:
 del directions[down]
 print (directions)

whenever i try to execute this code, i keep getting a message stating "IndexError: list assignment index out of range"




Aucun commentaire:

Enregistrer un commentaire