So the 'player' has to enter a number either 1 or 2. I need to use Python to make it so it will randomly choose a number so one will be 'good' and the player lives and the other 'bad' so the player dies.
Asked
Active
Viewed 134 times
-3
-
Oh it's python sorry should have said – Ted Arnott Oct 07 '15 at 19:50
-
Does this answer your question? [How to choose randomly between two values?](https://stackoverflow.com/questions/55399338/how-to-choose-randomly-between-two-values) – Gino Mempin Jul 21 '20 at 00:04
3 Answers
0
import random
c = random.choice([1, 2])
or
c = random.randrange(1, 3)

Lee Daniel Crocker
- 12,927
- 3
- 29
- 55
0
This is something that you could have Googled or consulted the documentation for... however, here's a basic implementation.
import random
x = random.randint(1, 2)

le_wofl
- 304
- 3
- 15
0
import random
variable_name = random.randint(x, y)
# x is the min and y is the max

Trolmaso
- 1
- 3
-
is there any need for the trailing comma at the end of the argument list? it is confusing... – L.Grozinger Jul 20 '20 at 20:50
-
1Sorry, didn't mean to put that there, there is no need for that comma, I will fix it – Trolmaso Jul 20 '20 at 20:53