vendredi 13 septembre 2019

How to call a function inside another function and make that run over and over

Firstly, they ask me to write a function that stimulates a rolling of ONE die. The function generates the random number in range(1,6). Take no parameters and returns the random number generated Then, it asks me to write another function that takes a SIZE of the list to create parameter. The function generates FIVE(size) random numbes in range (1,6) and assign each number to a list element. Then the function must call the first function to stimulate the roll of a die.

I have already tried to do the first function. But I am stuck at how to make the first function generate five numbers to assign to the list, and i dont understand the word "take a SIZE of the list". Does it mean len(list) ?

def roll_die():
  die = random.randint(1,6) #Import random
return die
die = roll_die()
def deal_hand(die):
   for index in range(len(list)) #List is a 5-element list
        list[index] = die
   return list[die]
   die = roll_dice()  
   step = step +1

I expect the output to be 
list = [1,2,4,5,6] 
when run again,
it will have random numbers like [2,4,5,1,3]




Aucun commentaire:

Enregistrer un commentaire