Kaiya Miller
Kaiya Miller

Reputation: 21

Random.randint and finding a number between two integers

I'm making a turn based game in Python. At one point, I need to generate a random number out of a hundred and see if it is in-between two numbers. It needs to be in the if statement.

elif random.randint(0,100) #is equal a number between 20 and 60

Is there a way to do this?

Upvotes: 0

Views: 697

Answers (2)

Cătălin Matei
Cătălin Matei

Reputation: 151

You can do

elif random.randint(0,100) in range(20, 61)

Upvotes: 2

Ayush
Ayush

Reputation: 3955

if low < random.randint(0,100) < high does the job well, unless you want to store the random value in a variable

Upvotes: 3

Related Questions