Python - Excluded from the list of values selected by random.choice() among random modules

Asked 2 years ago, Updated 2 years ago, 100 views

student = ['a', 'b', 'c', 'd', 'e', ' f', ' g' ] 

number = 0

import random

while number < 32:

    number += 1
    print(number, random.choice(student))
    input()

While creating a program that sets the order, the value selected as random.choice is not included in the next selection list, so that it is not a duplicate draw. What should I do?

python random

2022-09-22 18:48

1 Answers

You can remove the pulled items as shown below.

import random

student = ['a', 'b', 'c', 'd', 'e', 'f', 'g' ]

for _ in range(len(student)):
    choiceItem = random.choice(student)
    student.remove(choiceItem)
    print(choiceItem)


2022-09-22 18:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.