python-random 随机抽取学生编号

# 某班有N个学生,现在要选出M人(M 
  
import random


def select(n, m):
    num = [i for i in range(n)]
    num = random.sample(num, m)
    return num


if __name__ == '__main__':
    all_classmates = int(input('请输入班级总人数:'))
    sel_classmates = int(input('请输入总选择人数:'))
    print('已选出以下编号的同学:', *select(all_classmates, sel_classmates))

你可能感兴趣的:(python)