【发布时间】:2013-11-10 20:52:52
【问题描述】:
我们需要创建一个可用于“秘密圣诞老人”游戏的程序:
from random import *
people=[]
while True:
person=input("Enter a person participating.(end to exit):\n")
if person=="end": break
people.append(person)
shuffle(people)
for i in range(len(people)//2):
print(people[0],"buys for",people[1])
这是我开发的程序。截至目前,如果我输入 3 个人(例如 Bob、Ben、Bill) 它将返回“Ben 为 Bill 购买”,而没有人为 Ben 或 Bob 购买。我目前正试图让它输出“Bob 为 Ben 购买,Ben 为 Bill 购买,Bill 为 Bob 购买”,但到目前为止还没有成功。如果有人可以给我一个提示/基础来设置它,将不胜感激。另外,如果我的代码中有任何错误不允许我完成此操作,您能告诉我吗?谢谢。
【问题讨论】: