This is the full code The program is supposed to be something akin to a secret santa generator. Person a gives x number of gifts, persin b gives y number of gifts, and they don't get their own back. The problem is I only have very basic experiance with python, and this happened.
import random
number_of_people=int(input("How many participants?"))
list_of_names=[]
list_of_numbers=[]
origional_list_to_use=[]
for i in range (number_of_people):
name=input("What is the name of person "+str(i+1)+"?")
number=int(input("How many is "+name+" giving?"))
list_of_names.append(name)
list_of_numbers.append(number)
for i in range (number):
origional_list_to_use.append(name)
list_to_use=origional_list_to_use
count=0
while count<number_of_people:
giving=[]
for i in range (list_of_numbers[count]):
giving.append(random.choice(list_to_use))
if list_of_names[count] not in giving:
print(list_of_names[count]," gives to ",giving)
count=count+1
print(list_to_use)
for giving in list_to_use:
list_to_use.remove(giving)
else:
print("INVALID")
count=0
list_to_use=origional_list_to_use
gives an error, but why is my sequence empty? What am I doing wrong here? I'm thinking it may be in my list or use of random?
Sorry, here is the full error bit.
Traceback (most recent call last):
File "C:/Users/Name/Documents/Test.py", line 18, in <module>
giving.append(random.choice(list_to_use))
File "C:\Users\Name\AppData\Local\Programs\Python\Python38-32\lib\random.py", line 290, in choice
raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence
Aucun commentaire:
Enregistrer un commentaire