0

import random for i in range(5): value = random.randint(1, 6) print(value) 1.Why we use import random ? 2.why we write value variable instead of i ? 3.why we include random.randint ? 4.what is randint ?

1st Aug 2016, 11:03 AM
Rupam Das
Rupam Das - avatar
2 ответов
+ 3
1. import random imports the random module into your code which contains additional functions such as randint 2 not sure what you mean by that. we print the value variable because it is the one containing the generated numbers 3. random.randint calls a randint function from the imported random module. (see point 1), which generates a random number within designated range. 4. see point 3
1st Aug 2016, 11:58 AM
Vladimír Ondriska
Vladimír Ondriska - avatar
0
this code not iterates from 1 to 5 and prints them. it prints 5 RANDOM numbers between 1 and 6. so we need to import random. value variable is used to store random values to print them. if we use i instead we will get numbers from 1 to 5(not random). randint is the method that generates random numbers
1st Aug 2016, 12:57 PM
Nadir Novruzov