+ 4

Can someone explain this code?

import random print("This is console module") words = [ "Please" , "Help" , "Me" , "Merry" , "Christmas" ] for i in range(len(words)): random_index = random.randrange(len(words)) print(words[random_index]) del words[random_index]

20th Oct 2017, 1:31 PM
Poet🎭
Poet🎭 - avatar
1 Answer
0
import random print("This is console module") # print the statement words = [ "Please" , "Help" , "Me" , "Merry" , "Christmas" ] print (words) #it is list of words before further instructions # a list of words for i in range(len(words)): #it works up-to the elements in the list that is 5 random_index = random.randrange(len(words)) #it will select elements in the list randomly by index print(words[random_index]) # it will print that word which pick randomly del words[random_index] #it will delete that selected word print (words) #so at last no element will be in the list of words https://code.sololearn.com/cRV38JVziRI6/?ref=app
20th Oct 2017, 1:48 PM
Rewa Mathur