0
Module
import random for i in range(5): value = random.randint(1, 6) print(value) --------------------------- range(5) creates a list with elements: [0,1,2,3,4] why it has mentioned that range(5) and randint(1,6) creates a list with 6 elements which produces 5 numbers in range 1 to 6?
2 Respostas
+ 2
randint(1, 6) generates random number n so 1<= n <=6. It means that whenever you call this randint generator, it generates value n that could be any number from 1 to 6 including 1 and 6 themselves = total 6 numbers.
range(5) creates a sequence of 5 elements so variable i walks through all of them therefore generating randint value 5 times.
That is why you got five times random value in range 1 .. 6
0
Thanks for your clear response