【发布时间】:2021-12-31 11:10:51
【问题描述】:
我正在开发一个程序,该程序应该将女性舞伴分配给男性舞伴。用户选择一个男舞者,程序应该随机分配一个女舞者,然后从原始列表中删除两个选择的舞者。在我的编码课上,我从来没有被教过如何像这样随机分配。这是我到目前为止的代码:
import random
maledancers = {"Maciek", "Marek", "Marcel", "Carson", "Brett", "Connor"}
femaledancers = {"Renata", "Karolina", "Maja", "Natalia", "Olivia", "Meghan"}
print("You will be pairing the male dancers with the female dancers.")
print("You will select one of the male dancers and it will get paired with a female dancer randomly")
dancer = input("Out of the male dancers, please select one to be paired: ")
if dancer not in maledancers:
print("Your choice is not in the list of dancers, please re-enter a dancer from the list")
if dancer in maledancers:
print("Great we will now randomly give " + dancer + " a partner to dance with")
if dancer.isdigit():
print("The dancer can't have any numbers in their name. Try again please!")
如果有人对我可以在这里做什么有任何意见,我非常感谢任何帮助。如果您回答此问题,请显示代码更改。提前致谢!
【问题讨论】:
标签: python list dictionary random computer-science