Python3 实现来宾抽签

# coding=utf-8
#--author:valecalida--
#先将人名写入到列表中
#然后随机选取
import random
import os
members = []

mem_male = []
mem_female = []
def menu():
    print("*" * 50)
    print("1、新增来宾")
    print("2、查看来宾信息")
    print("3、随机匹配N对来宾")
    print("4、随机抽取一位来宾")
    print("5、退出本系统")
    print("*" * 50)

def total_member():
    print("男生有:",mem_male)
    print("女生有:",mem_female)
    global members
    members = mem_male + mem_female
    print("总人数有:%d"%(len(members)),"他们是:",members)


def catch_one():
    person = random.sample(members,1)
    print("恭喜",person,"被抽中了")


def guest_add():
    while True:
        sex = input("请输入来宾的性别(男1,女2。退出0):")
        if sex == '1':
            name = input("姓名:")
            mem_male.append(name)
        elif sex == '2':
            name = input("姓名:")
            mem_female.append(name)
        elif sex == '0':
            break
        else:
            print("输入有误")

def random_match():
    global renming
    renming = []
    name1 = random.choice(mem_male)
    name2 = random.choice(mem_female)
    renming.append(name1)
    renming.append(name2)
    print(renming)


def match_guest():
    i = 1
    most = int(input("您想匹配多少对来宾?\n请输入您想匹配的对数,要整数哦:"))
    while i <= most:
        random_match()
        i += 1

def start():
    while True:
        menu()
        userinput = input("请输入您想要进行的操作:")
        if userinput == '1':
            guest_add()
        elif userinput == '2':
            total_member()
        elif userinput == '3':
            match_guest()
        elif userinput == '4':
            catch_one()
        elif userinput == '5':
            exit()
        else:
            print("您的输入有误\n")

start()

 

你可能感兴趣的:(python)