0

How do I create an if elif else statement on a random number that the console creates? Python

Simply put, I am trying to make the console create a random # from 0-2. and based on that random number I plan to make an if elif else stayement. I think that means I will have to define X and set it equal to X? kind of like this X = [] or def x(): random#generator(0,2) and then use it like so if x == int(0): do a thing elif x == int(1): do a different thing else: do something else Basically I don't know what command to use to create the random number....

31st Oct 2017, 7:11 PM
Stef
Stef - avatar
8 Answers
+ 2
import random help(random)
31st Oct 2017, 7:13 PM
Oma Falk
Oma Falk - avatar
+ 2
Try to import only the random module. Then you will need to call it like this: random.randint (0,1)
1st Nov 2017, 4:21 PM
Porf
Porf - avatar
0
thank u both
1st Nov 2017, 3:39 PM
Stef
Stef - avatar
0
and I love the answer for the else statement porf!
1st Nov 2017, 3:40 PM
Stef
Stef - avatar
0
but I can't import a randit. in my code
1st Nov 2017, 4:15 PM
Stef
Stef - avatar
0
so would I just put in import random and then random.randint (1,0)?
1st Nov 2017, 4:24 PM
Stef
Stef - avatar
0
I'm just not sure what that would look like :)
1st Nov 2017, 4:31 PM
Stef
Stef - avatar