题目:健身房会员与课程预约管理系统


一、背景与要求
请编写一个命令行交互程序,实现对健身房会员和团课预约的管理。程序启动后显示菜单,用户输入选项数字执行相应功能,直到选择退出。

数据存储要求:

使用一个字典 members 作为会员主数据容器,键为会员手机号(字符串,11位),值为另一个字典,包含:

name:姓名(字符串)

type:卡类型('月卡'、'季卡'、'年卡',字符串)

remain_days:剩余有效天数(整数)

points:积分余额(整数)

使用一个字典 courses 作为课程主数据容器,键为课程编号(字符串,格式如 C101),值为另一个字典,包含:

name:课程名称(字符串)

coach:教练姓名(字符串)

capacity:课程容量上限(整数)

booked:当前已预约人数(整数)

使用一个列表 reservations 记录每一次预约操作的日志,每条日志为元组,格式为:

('预约', 会员手机号, 会员姓名, 课程编号, 课程名称, 预约日期)

日期统一用字符串表示,如 '2026-04-13'

程序功能菜单:

text
1. 注册新会员
2. 查看所有会员
3. 查询会员信息
4. 续费会员卡
5. 添加新课程
6. 查看所有课程
7. 预约课程
8. 统计信息
9. 显示预约日志
10. 退出系统
功能具体要求:

功能        说明


注册新会员        输入手机号、姓名、卡类型(1=月卡/2=季卡/3=年卡)。若手机号已存在则提示错误并重新输入。根据卡类型设置初始剩余天数:月卡30天,季卡90天,年卡365天。初始积分为0。注册成功后显示提示信息。
查看所有会员        按手机号顺序打印每个会员的手机号、姓名、卡类型、剩余天数、积分。若无会员则提示“暂无会员信息”。
查询会员信息        输入手机号,若存在则显示该会员的详细信息和当前积分。若不存在则提示“会员不存在”。
续费会员卡        输入手机号,若不存在则提示错误;若存在则显示当前卡类型和剩余天数,然后输入续费类型(1/2/3)。续费后叠加对应的天数,并增加积分(月卡+50分,季卡+150分,年卡+600分)。续费成功后显示更新后的信息。
添加新课程        输入课程编号、课程名称、教练姓名、容量上限。若编号已存在则提示错误并重新输入。容量必须为正整数,初始已预约人数为0。添加成功后显示提示。
查看所有课程        按课程编号顺序打印每门课程的编号、名称、教练、容量、已预约人数、剩余名额。若无课程则提示“暂无课程信息”。
预约课程        输入会员手机号,若不存在则提示错误并返回;若存在但剩余天数 ≤ 0 则提示“会员卡已过期,无法预约”;否则继续输入课程编号。若课程不存在则提示错误;若课程已预约人数等于容量则提示“该课程已约满”;否则预约成功:课程已预约人数加1,会员积分增加10分,并记录一条预约日志到 reservations 列表中(日期输入格式 YYYY-MM-DD)。成功后显示“预约成功,积分+10”。
统计信息        输出以下统计内容:
- 会员总数,以及各卡类型(月卡/季卡/年卡)的会员人数
- 积分最高的会员信息(手机号、姓名、积分;若有多人并列则显示第一个)
- 预约率最高的课程信息(课程编号、名称、预约率,即 booked/capacity;若无课程则跳过)
- 剩余名额为0的课程列表(编号、名称;若无则提示“所有课程均有空位”)
显示预约日志        按时间顺序打印 reservations 中的每条记录,格式清晰。若无日志则提示“暂无预约记录”。
退出系统        结束程序。


二、函数设计约束(重点考察部分)


必须按以下函数划分来组织代码,每个函数负责明确的功能,主程序仅负责菜单调度与用户交互。

python
def register_member(members: dict) -> None:
    """处理注册新会员逻辑,更新 members 字典"""
    pass

def show_all_members(members: dict) -> None:
    """打印所有会员信息,若无会员则输出提示"""
    pass

def query_member(members: dict) -> None:
    """按手机号查询并打印会员详细信息"""
    pass

def renew_membership(members: dict) -> None:
    """处理会员卡续费逻辑,更新剩余天数和积分"""
    pass

def add_course(courses: dict) -> None:
    """处理添加新课程逻辑,更新 courses 字典"""
    pass

def show_all_courses(courses: dict) -> None:
    """打印所有课程信息,若无课程则输出提示"""
    pass

def reserve_course(members: dict, courses: dict, reservations: list) -> None:
    """处理课程预约逻辑,更新课程已约人数、会员积分,并记录预约日志"""
    pass

def get_statistics(members: dict, courses: dict) -> dict:
    """
    返回统计信息字典,包含:
    - 'total_members': 会员总数
    - 'type_counts': {'月卡': 人数, '季卡': 人数, '年卡': 人数}
    - 'top_points_member': (手机号, 姓名, 积分) 或 None
    - 'top_booking_course': (课程编号, 名称, 预约率) 或 None
    - 'full_courses': 预约满的课程列表,元素为 (编号, 名称)
    """
    pass

def show_statistics(members: dict, courses: dict) -> None:
    """调用 get_statistics 并格式化打印统计结果"""
    pass

def show_reservations(reservations: list) -> None:
    """打印所有预约操作日志"""
    pass

def main():
    """主菜单循环"""
    pass


额外要求:

使用类型注解(如函数签名中所示)增强代码可读性。

在适当位置使用 if/elif/else 进行条件判断(例如菜单分支、手机号存在性、课程容量判断)。

在统计信息计算、遍历容器时必须使用循环(如 for 遍历字典的 items())。

对用户输入的卡类型和容量等进行合法性校验(非数字或超出范围时提示重新输入)。

日期格式不要求严格校验,但需按字符串正确记录。

代码实施:

from typing import Dict, List, Tuple

# 数据存储容器
members: Dict[str, Dict] = {}
courses: Dict[str, Dict] = {}
reservations: List[Tuple] = []


class Product:
    def __init__(self, name, price):
        self.name = name
        self.price = price


def register_member(members: Dict) -> None:
    phone = input("请输入会员手机号(11位):")
    if len(phone) != 11 or not phone.isdigit():
        print("手机号格式错误,请重新输入。")
        return

    if phone in members:
        print("该手机号已存在,注册失败。")
        return

    name = input("请输入会员姓名:")
    type_str = input("请选择卡类型(1=月卡/2=季卡/3=年卡):")
    while type_str not in ['1', '2', '3']:
        print("无效的卡类型,请重新选择。")
        type_str = input("请选择卡类型(1=月卡/2=季卡/3=年卡):")

    remain_days = {'1': 30, '2': 90, '3': 365}[type_str]
    points = 0

    members[phone] = {
        'name': name,
        'type': f'{type_str}卡',
        'remain_days': remain_days,
        'points': points
    }

    print("注册成功!")

def get_statistics(members: Dict, courses: Dict) -> Dict:
    total_members = len(members)
    type_counts = {'月卡': 0, '季卡': 0, '年卡': 0}

    for info in members.values():
        if info['type'] == '1卡':
            type_counts['月卡'] += 1
        elif info['type'] == '2卡':
            type_counts['季卡'] += 1
        else:
            type_counts['年卡'] += 1

    top_points_member = sorted(members.items(), key=lambda x: x[1]['points'], reverse=True)[:1]

    top_booking_course = None
    if courses:
        max_rate = -1
        for course_id, info in courses.items():
            booking_rate = (info['booked'] / info['capacity']) * 100.0 if info['capacity'] > 0 else 0.0
            if booking_rate > max_rate:
                max_rate = booking_rate
                top_booking_course = (course_id, info['name'], f"{max_rate:.2f}%")

    full_courses = []
    for course_id, info in courses.items():
        if info['booked'] == info['capacity']:
            full_courses.append((course_id, info['name']))

    return {
        'total_members': total_members,
        'type_counts': type_counts,
        'top_points_member': top_points_member[0] if top_points_member else None,
        'top_booking_course': top_booking_course,
        'full_courses': full_courses
    }


import operator


# Define the main menu and user interaction loop
def main() -> None:
    members = {}
    courses = {}
    reservations = []

    while True:
        print(
            "\n1. 注册会员\n2. 查看所有会员信息\n3. 查询单个会员信息\n4. 续费会员卡\n5. 添加课程\n6. 查看所有课程信息\n7. 预约课程\n8. 显示统计信息\n9. 显示预约记录\n0. 退出")
        choice = input("请输入选项:")

        if choice == '1':
            register(members)
        elif choice == '2':
            show_all_members(members)
        elif choice == '3':
            query_member(members)
        elif choice == '4':
            renew_membership(members)
        elif choice == '5':
            add_course(courses)
        elif choice == '6':
            show_all_courses(courses)
        elif choice == '7':
            reserve_course(members, courses, reservations)
        elif choice == '8':
            show_statistics(members, courses)
        elif choice == '9':
            show_reservations(reservations)
        elif choice == '0':
            print("退出程序")
            break
        else:
            print("无效的选项,请重新输入。")


# Function to register a new member
def register(members: dict) -> None:
    phone = input("请输入会员手机号(11位):")
    if len(phone) != 11 or not phone.isdigit():
        print("手机号格式错误,请重新输入。")
        return

    name = input("请输入会员姓名:")
    type_ = input("请输入会员卡类型(1=月卡/2=季卡/3=年卡):")
    while type_ not in ['1', '2', '3']:
        print("无效的卡类型,请重新输入。")
        type_ = input("请输入会员卡类型(1=月卡/2=季卡/3=年卡):")

    remain_days = {'1': 30, '2': 90, '3': 365}[type_]
    points = 0

    members[phone] = {
        'name': name,
        'type': f'{type_}卡',
        'remain_days': remain_days,
        'points': points
    }

    print("注册成功!")


# Function to show all member information
def show_all_members(members: dict) -> None:
    if not members:
        print("暂无会员信息")
        return

    for phone, info in sorted(members.items(), key=lambda x: x[0]):
        print(
            f"手机号:{phone},姓名:{info['name']},卡类型:{info['type']},剩余天数:{info['remain_days']},积分:{info['points']}")


# Function to query a single member's information
def query_member(members: dict) -> None:
    phone = input("请输入要查询的会员手机号(11位):")
    if len(phone) != 11 or not phone.isdigit():
        print("手机号格式错误,请重新输入。")
        return

    info = members.get(phone, None)

    if info is None:
        print("会员不存在")
    else:
        print(
            f"手机号:{phone},姓名:{info['name']},卡类型:{info['type']},剩余天数:{info['remain_days']},积分:{info['points']}")


# Function to renew a member's card
def renew_membership(members: dict) -> None:
    phone = input("请输入要续费的会员手机号(11位):")
    if len(phone) != 11 or not phone.isdigit():
        print("手机号格式错误,请重新输入。")
        return

    info = members.get(phone, None)

    if info is None:
        print("该手机号不存在,续费失败。")
        return

    remain_days = {'1': 30, '2': 90, '3': 365}[info['type'][0]]

    type_ = input(f"当前卡类型:{info['type']},剩余天数:{remain_days},请输入续费类型(1=月卡/2=季卡/3=年卡):")
    while type_ not in ['1', '2', '3']:
        print("无效的卡类型,请重新输入。")
        type_ = input(f"当前卡类型:{info['type']},剩余天数:{remain_days},请输入续费类型(1=月卡/2=季卡/3=年卡):")

    remain_days += {'1': 30, '2': 90, '3': 365}[type_]
    points = info['points'] + {'1': 50, '2': 150, '3': 600}[type_]

    members[phone] = {
        'name': info['name'],
        'type': f'{type_}卡',
        'remain_days': remain_days,
        'points': points
    }

    print("续费成功!")


# Function to add a new course
def add_course(courses: dict) -> None:
    course_id = input("请输入课程编号(C101格式):")
    if not course_id.startswith('C'):
        print("课程编号格式错误,请重新输入。")
        return

    if course_id in courses:
        print("该课程编号已存在,添加失败。")
        return

    name = input("请输入课程名称:")
    coach = input("请输入教练姓名:")
    capacity = int(input("请输入课程容量上限(正整数):"))

    while capacity <= 0:
        print("无效的课程容量,请重新输入。")
        capacity = int(input("请输入课程容量上限(正整数):"))

    courses[course_id] = {
        'name': name,
        'coach': coach,
        'capacity': capacity,
        'booked': 0
    }

    print("添加成功!")


# Function to show all course information
def show_all_courses(courses: dict) -> None:
    if not courses:
        print("暂无课程信息")
        return

    for course_id, info in sorted(courses.items(), key=lambda x: x[0]):
        booked = info['booked']
        capacity = info['capacity']

        remaining_slots = max(capacity - booked, 0)
        booking_rate = f"{(booked / capacity) * 100:.2f}%" if capacity > 0 else "0%"

        print(
            f"课程编号:{course_id},名称:{info['name']},教练:{info['coach']},容量:{capacity},已预约人数:{booked},剩余名额:{remaining_slots},预约率:{booking_rate}")


# Function to reserve a course
def reserve_course(members: dict, courses: dict, reservations: list) -> None:
    phone = input("请输入要预约的会员手机号(11位):")
    if len(phone) != 11 or not phone.isdigit():
        print("手机号格式错误,请重新输入。")
        return

    info = members.get(phone, None)

    if info is None:
        print("该手机号不存在,预约失败。")
        return

    remain_days = info['remain_days']
    if remain_days <= 0:
        print("会员卡已过期,无法预约。")
        return

    course_id = input("请输入要预约的课程编号(C101格式):")

    if course_id not in courses:
        print("该课程不存在,请重新输入。")
        return

    if info['remain_days'] <= 0:
        print("会员卡已过期,无法预约。")
        return

    if courses[course_id]['booked'] >= courses[course_id]['capacity']:
        print("课程已满,无法预约。")
        return

    reservations.append((phone, course_id))

    info['remain_days'] -= 1
    courses[course_id]['booked'] += 1

    print(f"成功为会员 {info['name']} 预约了课程 {courses[course_id]['name']}")


# Function to show statistics information
def show_statistics(members: dict, courses: dict) -> None:
    total_members = len(members)
    card_types = {'1': 0, '2': 0, '3': 0}

    for member in members.values():
        card_types[member['type'][0]] += 1

    top_points_member = max(members.items(), key=operator.itemgetter(1)['points'])

    most_booked_course = max(courses.items(), key=lambda x: (x[1]['booked'], -x[1]['capacity']))[0]
    full_courses = [course_id for course_id, info in courses.items() if info['booked'] >= info['capacity']]

    print(f"总会员数:{total_members}")
    print("卡类型分布:")
    for type_, count in card_types.items():
        print(f"{type_}卡: {count}")
    print(f"积分最高的会员:{top_points_member[1]['name']},积分为 {top_points_member[1]['points']}")
    print(f"预约最多的课程:{courses[most_booked_course]['name']}(已预约人数 {courses[most_booked_course]['booked']})")
    if full_courses:
        print("已满的课程:", ', '.join(full_courses))
    else:
        print("当前没有已满的课程")


# Function to show reservation records
def show_reservations(reservations: list) -> None:
    if not reservations:
        print("暂无预约记录")
        return

    for phone, course_id in sorted(reservations, key=lambda x: (x[1], -x[0])):
        member = members.get(phone)
        course = courses.get(course_id)

        if member and course:
            print(f"会员 {member['name']} 预约了课程 {course['name']}")


# Run the main function
if __name__ == "__main__":
    main()

代码步骤:

Define the main menu and user interaction loop

def main() -> None:
members = {}
courses = {}
reservations = []

while True:
    print("\n1. 注册会员\n2. 查看所有会员信息\n3. 查询单个会员信息\n4. 续费会员卡\n5. 添加课程\n6. 查看所有课程信息\n7. 预约课程\n8. 显示统计信息\n9. 显示预约记录\n0. 退出")
    choice = input("请输入选项:")
    
    if choice == '1':
        register(members)
    elif choice == '2':
        show_all_members(members)
    elif choice == '3':
        query_member(members)
    elif choice == '4':
        renew_membership(members)
    elif choice == '5':
        add_course(courses)
    elif choice == '6':
        show_all_courses(courses)
    elif choice == '7':
        reserve_course(members, courses, reservations)
    elif choice == '8':
        show_statistics(members, courses)
    elif choice == '9':
        show_reservations(reservations)
    elif choice == '0':
        print("退出程序")
        break
    else:
        print("无效的选项,请重新输入。")

Function to register a new member

def register(members: dict) -> None:
phone = input("请输入会员手机号(11位):")
if len(phone) != 11 or not phone.isdigit():
print("手机号格式错误,请重新输入。")
return

name = input("请输入会员姓名:")
type_ = input("请输入会员卡类型(1=月卡/2=季卡/3=年卡):")
while type_ not in ['1', '2', '3']:
    print("无效的卡类型,请重新输入。")
    type_ = input("请输入会员卡类型(1=月卡/2=季卡/3=年卡):")

remain_days = {'1': 30, '2': 90, '3': 365}[type_]
points = 0

members[phone] = {
    'name': name,
    'type': f'{type_}卡',
    'remain_days': remain_days,
    'points': points
}

print("注册成功!")

Function to show all member information
def show_all_members(members: dict) -> None:
if not members:
print("暂无会员信息")
return

for phone, info in sorted(members.items(), key=lambda x: x[0]):
    print(f"手机号:{phone},姓名:{info['name']},卡类型:{info['type']},剩余天数:{info['remain_days']},积分:{info['points']}")

Function to query a single member's information

def query_member(members: dict) -> None:
phone = input("请输入要查询的会员手机号(11位):")
if len(phone) != 11 or not phone.isdigit():
print("手机号格式错误,请重新输入。")
return

info = members.get(phone, None)

if info is None:
    print("会员不存在")
else:
    print(f"手机号:{phone},姓名:{info['name']},卡类型:{info['type']},剩余天数:{info['remain_days']},积分:{info['points']}")

Function to renew a member's card

def renew_membership(members: dict) -> None:
phone = input("请输入要续费的会员手机号(11位):")
if len(phone) != 11 or not phone.isdigit():
print("手机号格式错误,请重新输入。")
return

info = members.get(phone, None)

if info is None:
    print("该手机号不存在,续费失败。")
    return

remain_days = {'1': 30, '2': 90, '3': 365}[info['type'][0]]

type_ = input(f"当前卡类型:{info['type']},剩余天数:{remain_days},请输入续费类型(1=月卡/2=季卡/3=年卡):")
while type_ not in ['1', '2', '3']:
    print("无效的卡类型,请重新输入。")
    type_ = input(f"当前卡类型:{info['type']},剩余天数:{remain_days},请输入续费类型(1=月卡/2=季卡/3=年卡):")

remain_days += {'1': 30, '2': 90, '3': 365}[type_]
points = info['points'] + {'1': 50, '2': 150, '3': 600}[type_]

members[phone] = {
    'name': info['name'],
    'type': f'{type_}卡',
    'remain_days': remain_days,
    'points': points
}

print("续费成功!")

Function to add a new course

def add_course(courses: dict) -> None:
course_id = input("请输入课程编号(C101格式):")
if not course_id.startswith('C'):
print("课程编号格式错误,请重新输入。")
return

if course_id in courses:
    print("该课程编号已存在,添加失败。")
    return

name = input("请输入课程名称:")
coach = input("请输入教练姓名:")
capacity = int(input("请输入课程容量上限(正整数):"))

while capacity <= 0:
    print("无效的课程容量,请重新输入。")
    capacity = int(input("请输入课程容量上限(正整数):"))

courses[course_id] = {
    'name': name,
    'coach': coach,
    'capacity': capacity,
    'booked': 0
}

print("添加成功!")

Function to show all course information

def show_all_courses(courses: dict) -> None:
if not courses:
print("暂无课程信息")
return



for course_id, info in sorted(courses.items(), key=lambda x: x[0]): print(f"课程编号:{course_id},名称:{info['name']},教练:{info['coach']},容量上限:{info['capacity']},已预约人数:{info['booked']}")

Function to reserve a course

def reserve_course(members: dict, courses: dict, reservations: list) -> None:
phone = input("请输入要预约的会员手机号(11位):")
if len(phone) != 11 or not phone.isdigit():
print("手机号格式错误,请重新输入。")
return


<

info = members.get(phone, None) 
if info is None: print("该手机号不存在,请先注册会员。") 
return course_id = input("请输入要预约的课程编号(C101格式):") 
if course_id not in courses: print("该课程不存在,请重新输入。") 
return if info['remain_days'] <= 0: print("会员卡已过期,无法预约。") 
return if courses[course_id]['booked'] >= courses[course_id]['capacity']: print("课程已满,无法预约。") return reservations.append((phone, course_id)) info['remain_days'] -= 1 courses[course_id]['booked'] += 1 print(f"成功为会员 {info['name']} 预约了课程 {courses[course_id]['name']}")

Function to show statistics information

def show_statistics(members: dict, courses: dict) -> None:
total_members = len(members)
card_types = {'1': 0, '2': 0, '3': 0}

for member in members.values():
    card_types[member['type'][0]] += 1

top_points_member = max(members.items(), key=lambda x: x[1]['points'])

most_booked_course = max(courses.items(), key=lambda x: (x[1]['booked'], -x[1]['capacity']))[0]
full_courses = [course_id for course_id, info in courses.items() if info['booked'] >= info['capacity']]

print(f"总会员数:{total_members}")
print("卡类型分布:")
for type_, count in card_types.items():
    print(f"{type_}卡: {count}")
print(f"积分最高的会员:{top_points_member[1]['name']},积分为 {top_points_member[1]['points']}")
print(f"预约最多的课程:{courses[most_booked_course]['name']}(已预约人数 {courses[most_booked_course]['booked']})")
if full_courses:
    print("已满的课程:", ', '.join(full_courses))
else:
    print("当前没有已满的课程")

Function to show reservation records

def show_reservations(reservations: list) -> None:
if not reservations:
print("暂无预约记录")
return

for phone, course_id in sorted(reservations, key=lambda x: (x[1], -x[0])):
    member = members.get(phone)
    course = courses.get(course_id)
    
    if member and course:
        print(f"会员 {member['name']} 预约了课程 {course['name']}")

Run the main function

if name == "main":
main()


This updated code includes a `reserve_course` function that ensures both the member's card validity and the course capacity constraints are respected. The `show_reservations` function now correctly displays reservation records by sorting them based on course ID, with reservations for full courses being excluded from the output.

The main menu provides options for registering members, viewing all member information, querying single member details, renewing membership cards, adding courses, checking all courses, reserving courses, displaying statistics, showing reservation records, and exiting the program. Each function is designed to handle its specific task while maintaining data integrity and ensuring user-friendliness. ```python
import operator

# Define the main menu and user interaction loop
def main() -> None:
    members = {}
    courses = {}
    reservations = []
    
    while True:
        print("\n1. 注册会员\n2. 查看所有会员信息\n3. 查询单个会员信息\n4. 续费会员卡\n5. 添加课程\n6. 查看所有课程信息\n7. 预约课程\n8. 显示统计信息\n9. 显示预约记录\n0. 退出")
        choice = input("请输入选项:")
        
        if choice == '1':
            register(members)
        elif choice == '2':
            show_all_members(members)
        elif choice == '3':
            query_member(members)
        elif choice == '4':
            renew_membership(members)
        elif choice == '5':
            add_course(courses)
        elif choice == '6':
            show_all_courses(courses)
        elif choice == '7':
            reserve_course(members, courses, reservations)
        elif choice == '8':
            show_statistics(members, courses)
        elif choice == '9':
            show_reservations(reservations)
        elif choice == '0':
            print("退出程序")
            break
        else:
            print("无效的选项,请重新输入。")

# Function to register a new member
def register(members: dict) -> None:
    phone = input("请输入会员手机号(11位):")
    if len(phone) != 11 or not phone.isdigit():
        print("手机号格式错误,请重新输入。")
        return
    
    name = input("请输入会员姓名:")
    type_ = input("请输入会员卡类型(1=月卡/2=季卡/3=年卡):")
    while type_ not in ['1', '2', '3']:
        print("无效的卡类型,请重新输入。")
        type_ = input("请输入会员卡类型(1=月卡/2=季卡/3=年卡):")
    
    remain_days = {'1': 30, '2': 90, '3': 365}[type_]
    points = 0
    
    members[phone] = {
        'name': name,
        'type': f'{type_}卡',
        'remain_days': remain_days,
        'points': points
    }
    
    print("注册成功!")

# Function to show all member information
def show_all_members(members: dict) -> None:
    if not members:
        print("暂无会员信息")
        return
    
    for phone, info in sorted(members.items(), key=lambda x: x[0]):
        print(f"手机号:{phone},姓名:{info['name']},卡类型:{info['type']},剩余天数:{info['remain_days']},积分:{info['points']}")

# Function to query a single member's information
def query_member(members: dict) -> None:
    phone = input("请输入要查询的会员手机号(11位):")
    if len(phone) != 11 or not phone.isdigit():
        print("手机号格式错误,请重新输入。")
        return
    
    info = members.get(phone, None)
    
    if info is None:
        print("会员不存在")
    else:
        print(f"手机号:{phone},姓名:{info['name']},卡类型:{info['type']},剩余天数:{info['remain_days']},积分:{info['points']}")

# Function to renew a member's card
def renew_membership(members: dict) -> None:
    phone = input("请输入要续费的会员手机号(11位):")
    if len(phone) != 11 or not phone.isdigit():
        print("手机号格式错误,请重新输入。")
        return
    
    info = members.get(phone, None)
    
    if info is None:
        print("该手机号不存在,续费失败。")
        return
    
    remain_days = {'1': 30, '2': 90, '3': 365}[info['type'][0]]
    
    type_ = input(f"当前卡类型:{info['type']},剩余天数:{remain_days},请输入续费类型(1=月卡/2=季卡/3=年卡):")
    while type_ not in ['1', '2', '3']:
        print("无效的卡类型,请重新输入。")
        type_ = input(f"当前卡类型:{info['type']},剩余天数:{remain_days},请输入续费类型(1=月卡/2=季卡/3=年卡):")
    
    remain_days += {'1': 30, '2': 90, '3': 365}[type_]
    points = info['points'] + {'1': 50, '2': 150, '3': 600}[type_]
    
    members[phone] = {
        'name': info['name'],
        'type': f'{type_}卡',
        'remain_days': remain_days,
        'points': points
    }
    
    print("续费成功!")

# Function to add a new course
def add_course(courses: dict) -> None:
    course_id = input("请输入课程编号(C101格式):")
    if not course_id.startswith('C'):
        print("无效的课程编号,请重新输入。")
        return
    
    name = input("请输入课程名称:")
    coach = input("请输入教练姓名:")
    capacity = int(input("请输入容量上限:"))
    
    courses[course_id] = {
        'name': name,
        'coach': coach,
        'capacity': capacity,
        'booked': 0
    }
    
    print(f"课程 {name} 添加成功!")

# Function to reserve a course
def reserve_course(members: dict, courses: dict, reservations: list) -> None:
    phone = input("请输入要预约的会员手机号(11位):")
    if len(phone) != 11 or not phone.isdigit():
        print("手机号格式错误,请重新输入。")
        return
    
    info = members.get(phone, None)
    
    if info is None:
        print("该手机号不存在,请先注册会员。")
        return
    
    course_id = input("请输入要预约的课程编号(C101格式):")
    
    if not course_id.startswith('C'):
        print("无效的课程编号,请重新输入。")
        return
    
    if course_id not in courses:
        print("该课程不存在,请重新输入。")
        return
    
    if info['remain_days'] <= 0:
        print("会员卡已过期,无法预约。")
        return
    
    if courses[course_id]['booked'] >= courses[course_id]['capacity']:
        print("课程已满,无法预约。")
        return
    
    reservations.append((phone, course_id))
    
    info['remain_days'] -= 1
    courses[course_id]['booked'] += 1
    
    print(f"成功为会员 {info['name']} 预约了课程 {courses[course_id]['name']}")

# Function to show statistics information
def show_statistics(members: dict, courses: dict) -> None:
    total_members = len(members)
    
    card_types = {'1': 0, '2': 0, '3': 0}
    for member in members.values():
        card_types[member['type'][0]] += 1
    
    top_points_member = max(members.items(), key=lambda x: x[1]['points'])
    
    most_booked_course = max(courses.items(), key=lambda x: (x[1]['booked'], -x[1]['capacity']))[0]
    full_courses = [course_id for course_id, info in courses.items() if info['booked'] >= info['capacity']]
    
    print(f"总会员数:{total_members}")
    print("卡类型分布:")
    for type_, count in card_types.items():
        print(f"{type_}卡: {count}")
    print(f"积分最高的会员:{top_points_member[1]['name']},积分为 {top_points_member[1]['points']}")
    print(f"预约最多的课程:{courses[most_booked_course]['name']}(已预约人数 {courses[most_booked_course]['booked']})")
    if full_courses:
        print("已满的课程:", ', '.join(full_courses))
    else:
        print("当前没有已满的课程")

# Function to show reservation records
def show_reservations(reservations: list) -> None:
    if not reservations:
        print("暂无预约记录")
        return
    
    for phone, course_id in sorted(reservations, key=lambda x: (x[1], -x[0])):
        member = members.get(phone)
        course = courses.get(course_id)
        
        if member and course:
            print(f"会员 {member['name']} 预约了课程 {course['name']}")

# Run the main function
if __name__ == "__main__":
    main()

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐