我正在开发一个程序,它将模拟秘密圣诞老人的分类帽。我试图让程序有一个错误陷阱,以防止人们获得自己的名字,但我不能让程序选择一个新的名称,如果有人得到自己的名字。我遇到的另一个问题是程序总是过早退出。在
我的代码是: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)