import random
def rand(_min_, _max_, _times_, _type_):
t = 0
check = []
while t != _times_:
num = random.randint(_min_, _max_)
if not (num in check):
check.append(num)
t += 1
check.sort(reverse=False)
if _type_ == 'class':
for result in check:
print(str(result)+"号")
elif _type_ == 'group':
for result in check:
print(str(result)+"组")
def main():
while True:
opr = input("\n请选择功能: (输入数字后按回车)\n1. 随机点名\n2. 随机点组\n3. 退出\n>>> ")
if opr == '1':
min_ = int(input("\n输入学号范围: (1-54):\n最小学号: "))
max_ = int(input("最大学号: "))
times_ = int(input("输入抽取人数(小于" + str(max_ - min_ + 1) + "): "))
print("点名结果: ")
rand(_max_=max_, _min_=min_, _times_=times_, _type_='class')
input("按回车键返回主菜单. ")
elif opr == '2':
times_ = int(input("\n抽取小组数量: "))
print("点名结果: ")
rand(_min_=1, _max_=9, _times_=times_, _type_='group')
input("按回车键返回主菜单. ")
elif opr == '3':
exit(0)
if __name__ == '__main__':
main()