I have a list, nums, and I want to use the random module to pick an element from the list that isn't 0.
So far, I have:
nums = [25, 0, 50, 0, 2, 45, 0]
for numbers in nums:
for numbers != 0:
s = random.choice(nums)
print(s)
But this doesn't seem to work. I expect s to be one of [25, 50, 2, 45] How can I achieve this?
Aucun commentaire:
Enregistrer un commentaire