I have a python list with some numbers in it and I want to achieve that press keyboard can return a different number. This is my code.
import random
import os
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
b = random.sample(a, 1)
while True:
print(b)
os.system('pause')
But everytime I press space the returned element is the same, how can I make it return a different number?
CodePudding user response:
import random
import os
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
while True:
b = random.sample(a, 1)
print(b)
os.system('pause')
A random sample has to be taken every iteration