+ 2
I have some questions on the random module.
I am working on a game that requires random, and I need to mention it two times with the same result: greetings = ['hello', 'hi'] x = random.randrange[greetings(2)] print(x) print(x) however the results of 'x' are different between the two prints. May I ask how to make them the same?
3 Respuestas
+ 2
Greetings is a list, and not callable.
If you're just trying to get a random selection from a list, try choice instead:
x = random.choice(greetings)
+ 2
yes, but may I ask how do you print 'x' two times with for example hello?
+ 1
That shouldn't be possible for it to print two different results from the same variable. When you call the random library, and use the choice function, it returns the result and saves it into x. you can call it a hundred times and x will not change until you assign it another value.
If this is happening in your game, it's possible you're either calling random twice or x is being assigned more than once.