[Tutor] Need help with python game program
Dave Angel
davea at ieee.org
Wed Jul 1 04:29:47 CEST 2009
jonathan wallis wrote:
> My problem is simple, is their a way to make a variable equal multiple
> numbers? Such as X = 5 through 10, and then the program makes x equal
> something random 5 through 10, or something similar.
> <much snipping>
>
For a short question, why did you quote an entire mailing list digest?
Answer to your question, certainly a variable can "equal" multiple
numbers. Several ways:
1) one at a time. X=5, then later X=7.332
2) a list of values X = [5.3, 8.001, 17, 2]
3) a dictionary X = {"tom":3, "dick":42, "harry":12}
4) a class. Sky's the limit here
As for random, look up the random.uniform() and random.randint() functions.
Did you have a particular programming language in mind? I've been
assuming Python, but you might be thinking something else. Have you any
experience in any other language?
DaveA
More information about the Tutor
mailing list