+ 1
I don't know what is the randint module in python
I want example code and explainations
3 Respuestas
+ 3
random is the module and randint is a function from the module random.
You use the function like this :
Example 1:
import random
a = random.randint(1,4)
print(a)
Example 2:
from random import randint
a = randint(1,4)
print(a)
the randint function will chose an integer value between the two valuea given as parameters. The number is chosen uniformly at random. You have the same probability to get any of the possible output.
So random(1,4) will return 1, 2, 3 or 4. with a 25% chance each.
0
"I want example code and explanations"
Demanding are we?
There is no randint module. 'randint' actually belongs to the "random" module.
randint is a function that accepts two arguments. The first is the starting integer number, the second being the ending point integer number. Then returns an integer value between those two.
import random as r
x = r.randint ( 5 , 9 )
print ( x )
#output: 7
0
idek tbh