我正在研究一個程序,將模擬祕密聖誕老人的排序帽子。我試圖讓程序有一個錯誤陷阱來阻止人們獲取自己的名字,但是我無法讓程序在某人獲得自己的名字時選擇一個新名字。我遇到的另一個問題是該程序過早退出。祕密聖誕老人排序帽子
這裏是我的代碼:
import random
print "Testing Arrays"
Names=[0,1,2,3,4]
#0 - Travis
#1 - Eric
#2 - Bob
#3 - Tim
#4 - Dhyan
x = 1
z = True
def pick(x):
while (z == True):
#test=input("Is your Name Travis?")
choice = random.choice(Names) #Picks a random choice from Names Array
if (choice == 0): #If it's Travis
test=input("Is your Name Travis?") #Asking user if they're Rabbit
if(test == "Yes"):
return "Pick Again"
elif(test== "No"):
return "You got Travis"
Names.remove(1)
break
elif (choice == 1):
test=input("Is your Name Eric?")
if(test=="Yes"):
return "Pick Again"
elif(test=="No"):
Names.remove(2)
return "You got Eric"
break
print pick(1)