如何把不同的任务交给不同的人?
how to give diffrent tasks to diffrent people?
所以我有一个学校项目来制作一个 python 程序,给人们不同的任务。我是 python 的新手,所以我编写了这样的代码:
from random import *
tasks = [input("task: " ), input("task: " ), input("task: " ), input("task: " ), input("task: " ),
input("task: " ) ]
person1 = [input("name: ")]
person2 = [input("name: ")]
person3 = [input("name: ")]
person4 = [input("name: ")]
shuffle(tasks)
first = str(person1) + str(choice(tasks))
second = str(person2) + str(choice(tasks))
third = str(person3) + str(choice(tasks))
fourth = str(person4) + str(choice(tasks))
print (first)
print (second)
print (third)
print (fourth)
但有时它会为两个或更多人分配相同的任务。我怎样才能让它给每个人分配不同的任务?
因为此时 tasks
已经洗牌,所以使用 choice(tasks)
是不正确的。只需执行 first = tasks[0]
、second = tasks[1]
等
所以我有一个学校项目来制作一个 python 程序,给人们不同的任务。我是 python 的新手,所以我编写了这样的代码:
from random import *
tasks = [input("task: " ), input("task: " ), input("task: " ), input("task: " ), input("task: " ),
input("task: " ) ]
person1 = [input("name: ")]
person2 = [input("name: ")]
person3 = [input("name: ")]
person4 = [input("name: ")]
shuffle(tasks)
first = str(person1) + str(choice(tasks))
second = str(person2) + str(choice(tasks))
third = str(person3) + str(choice(tasks))
fourth = str(person4) + str(choice(tasks))
print (first)
print (second)
print (third)
print (fourth)
但有时它会为两个或更多人分配相同的任务。我怎样才能让它给每个人分配不同的任务?
因为此时 tasks
已经洗牌,所以使用 choice(tasks)
是不正确的。只需执行 first = tasks[0]
、second = tasks[1]
等