Reputation: 23
guys.
I'm trying to implement this logical condition in Python. I have to choose between a random number from 0 to 1 but save them both in two variables, so that the first variable is the value I'm interested in, while in the second there's the other value.
Something like:
x, y = random.sample(0,1)
But it's not working. How can I do it?
Upvotes: 1
Views: 51
Reputation: 475
This should help. It selects two values from [0, 1] without repetitions:
import random
x, y = random.sample([0, 1], 2)
Upvotes: 1
Reputation: 1500
You could use the shuffle
method:
import random
results = [0, 1]
random.shuffle(results)
x = results[0]
y = results[1]
Upvotes: 0
Reputation: 81
x = random.sample(0, 1)
y = random.sample(0, 1)
doing this might just make a way to simply make 2 separate values with 2 different lines.
Upvotes: 0