Sean.D Sean.D - 3 months ago 22
Python Question

Random picking 3 chosen numbers

Ok, I am creating a game and no matter what I do, it just isn't working. So I have 3 numbers chosen, 25,50,75.
I want to be able to random pick one of them. Then I will need to be able to add it to a total making it obviously an integer. I have imported random. I have tried random.sample but I can't get that one to be an number that I can add. I tried random.randint and that did not work at all. I have tried looking it up but it is pretty much all random in a range and not specific. Any ideas? Thanks in advance. I am using python 3.4.3.

Answer

Use random.choice:

>>> import random
>>> random.choice([25,50,75])
25
>>> random.choice([25,50,75])
25
>>> random.choice([25,50,75])
75