一.题目题目健身房会员与课程预约管理系统 一、背景与要求 请编写一个命令行交互程序实现对健身房会员和团课预约的管理。程序启动后显示菜单用户输入选项数字执行相应功能直到选择退出。数据存储要求使用一个字典 members 作为会员主数据容器键为会员手机号字符串11位值为另一个字典包含name姓名字符串type卡类型月卡、季卡、年卡字符串remain_days剩余有效天数整数points积分余额整数使用一个字典 courses 作为课程主数据容器键为课程编号字符串格式如 C101值为另一个字典包含name课程名称字符串coach教练姓名字符串capacity课程容量上限整数booked当前已预约人数整数使用一个列表 reservations 记录每一次预约操作的日志每条日志为元组格式为(预约, 会员手机号, 会员姓名, 课程编号, 课程名称, 预约日期)日期统一用字符串表示如 2026-04-13程序功能菜单text注册新会员查看所有会员查询会员信息续费会员卡添加新课程查看所有课程预约课程统计信息显示预约日志退出系统 功能具体要求功能 说明 注册新会员 输入手机号、姓名、卡类型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 字典 passdef show_all_members(members: dict) - None: 打印所有会员信息若无会员则输出提示 passdef query_member(members: dict) - None: 按手机号查询并打印会员详细信息 passdef renew_membership(members: dict) - None: 处理会员卡续费逻辑更新剩余天数和积分 passdef add_course(courses: dict) - None: 处理添加新课程逻辑更新 courses 字典 passdef show_all_courses(courses: dict) - None: 打印所有课程信息若无课程则输出提示 passdef reserve_course(members: dict, courses: dict, reservations: list) - None: 处理课程预约逻辑更新课程已约人数、会员积分并记录预约日志 passdef get_statistics(members: dict, courses: dict) - dict: 返回统计信息字典包含total_members: 会员总数type_counts: {月卡: 人数, 季卡: 人数, 年卡: 人数}top_points_member: (手机号, 姓名, 积分) 或 Nonetop_booking_course: (课程编号, 名称, 预约率) 或 Nonefull_courses: 预约满的课程列表元素为 (编号, 名称) passdef show_statistics(members: dict, courses: dict) - None: 调用 get_statistics 并格式化打印统计结果 passdef show_reservations(reservations: list) - None: 打印所有预约操作日志 passdef main(): 主菜单循环 pass 额外要求使用类型注解如函数签名中所示增强代码可读性。在适当位置使用 if/elif/else 进行条件判断例如菜单分支、手机号存在性、课程容量判断。在统计信息计算、遍历容器时必须使用循环如 for 遍历字典的 items()。对用户输入的卡类型和容量等进行合法性校验非数字或超出范围时提示重新输入。日期格式不要求严格校验但需按字符串正确记录。二.代码str1 1. 注册新会员2. 查看所有会员3. 查询会员信息4. 续费会员卡5. 添加新课程6. 查看所有课程7. 预约课程8. 统计信息9. 显示预约日志10. 退出系统menbers{12345678911:{name:moa,type:季卡,remain_days:57,points:50,},12345678912:{name:Taehyun,type:年卡,remain_days:90,points:150,}}courses{A001:{name:瑜伽,coach:Yeonjun,capacity:40,booked:0,},A002:{name:跑步,coach:Soobin,capacity:40,booked:0,}}reservations[]def register_member(members: dict) - None:处理注册新会员逻辑更新 members 字典while True:phone input(请输入11位手机号)if len(phone) ! 11 or not phone.isdigit():print(请输入正确的11位手机号码)continueif phone in members:print(该手机号已被注册请重试)continuebreakname input(请输入姓名: ).strip()while True:print(卡类型1.月卡 2.季卡 3.年卡)type_choice input(请输入选项(1/2/3): ).strip()if type_choice 1:card_type 月卡days 30breakelif type_choice 2:card_type 季卡days 90breakelif type_choice 3:card_type 年卡days 365breakelse:print(输入无效请输入选项(1/2/3))members[phone] {name: name,type: card_type,remain_days: days,points: 0}print(f会员 {name} 注册成功卡类型{card_type}剩余天数{days}天)def show_all_members(members: dict) - None:打印所有会员信息若无会员则输出提示if not members:print(暂无会员信息)returnfor phone in sorted(members.keys()):info members[phone]print(f手机号{phone} 姓名{info[name]} 卡类型{info[type]} 剩余天数{info[remain_days]} 积分{info[points]})def query_member(members: dict) - None:按手机号查询并打印会员详细信息phone input(请输入会员手机号: ).strip()if phone not in members:print(会员不存在)returninfo members[phone]print(f会员详情\n手机号{phone}\n姓名{info[name]}\n卡类型{info[type]}\n剩余天数{info[remain_days]}\n当前积分{info[points]})def renew_membership(members: dict) - None:处理会员卡续费逻辑更新剩余天数和积分phone input(请输入会员手机号: ).strip()if phone not in members:print(会员不存在无法续费)returnmember members[phone]print(f当前卡类型{member[type]}剩余天数{member[remain_days]}天)print(续费类型1.月卡(30天,50分) 2.季卡(90天,150分) 3.年卡(365天,600分))while True:choice input(请选择续费类型1.月卡 2.季卡 3.年卡)if choice not in [1, 2, 3]:print(输入无效请输入选项(1/2/3))continuebreakcard_map {1: (月卡, 30),2: (季卡, 90),3: (年卡, 365),}new_type, add_days, add_points card_map[choice]member[remain_days] add_daysmember[points] add_pointsmember[type] new_typeprint(f您已续费成功{member[type]}卡剩余{member[remain_days]}天总积分{member[points]})def add_course(courses: dict) - None:处理添加新课程逻辑更新 courses 字典while True:cid input(请输入课程编号)if cid in courses:print(编号已存在请重新输入)continueif not cid:print(编号不能为空)continuebreakname input(课程名称: ).strip()coach input(教练姓名: ).strip()while True:cap_str input(课程容量上限(正整数): ).strip()if cap_str.isdigit() and int(cap_str) 0:capacity int(cap_str)breakelse:print(错误请输入正整数)courses[cid] {name: name,coach: coach,capacity: capacity,booked: 0}def show_all_courses(courses: dict) - None:打印所有课程信息若无课程则输出提示if not courses:print(暂无课程信息)returnsorted_cids sorted(courses.keys())print(所有课程信息)for cid in sorted_cids:info courses[cid]remain info[capacity] - info[booked]print(f编号{cid},名称{info[name]},教练{info[coach]},总容量{info[capacity]},已预约{info[booked]},剩余名额{remain})def reserve_course(members: dict, courses: dict, reservations: list) - None:处理课程预约逻辑更新课程已约人数、会员积分并记录预约日志phone input(请输入会员手机号).strip()if phone not in members:print(该会员不存在)returnmember members[phone]if member[remain_days] 0:print(您的会员卡已过期无法进行预约)returncid input(请输入课程编号).split()if cid not in courses:print(该课程不存在)returncourse courses[cid]if course[booked] course[capacity]:print(该课程已约满)returncourse[booked] 1member[points] 10log (预约, phone, member[name], cid, course[name])reservations.append(log)print(预约成功积分10)def get_statistics(members: dict, courses: dict) - dict:返回统计信息字典包含- total_members: 会员总数- type_counts: {月卡: 人数, 季卡: 人数, 年卡: 人数}- top_points_member: (手机号, 姓名, 积分) 或 None- top_booking_course: (课程编号, 名称, 预约率) 或 None- full_courses: 预约满的课程列表元素为 (编号, 名称)total_members len(members)type_counts {月卡: 0, 季卡: 0, 年卡: 0}top_points_member Noneif members:max_points -1for phone, info in members.items():current_points info[points]if current_points max_points:max_points current_pointstop_points_member (phone, info[name], current_points)top_booking_course Nonefull_courses []if courses:max_rate -1.0for cid, info in courses.items():capacity info[capacity]booked info[booked]booking_rate booked / capacity if capacity ! 0 else 0.0if booking_rate max_rate:max_rate booking_ratetop_booking_course (cid, info[name], booking_rate)if booked capacity:full_courses.append((cid, info[name]))return {total_members: total_members,type_counts: type_counts,top_points_member: top_points_member,top_booking_course: top_booking_course,full_courses: full_courses}def show_statistics(members: dict, courses: dict) - None:调用 get_statistics 并格式化打印统计结果str2 get_statistics(menbers, courses)print(统计信息)print(f会员总数为{str2[total_members]})type_count1 str2[type_counts]print(f月卡会员有{type_count1[月卡]}人季卡会员有{type_count1[季卡]}人年卡会员有{type_count1[年卡]}人)if str2[top_points_member]:phone, name, points str2[top_points_member]print(f积分最高会员为手机号{phone},姓名{name},积分{points})else:print(暂无会员)if str2[top_booking_course]:cid, name, rate str2[top_booking_course]print(f预约率最高课程编号 {cid}名称 {name}预约率 {rate:.2%})else:print(暂无课程无预约率信息)full_list str2[full_courses]if full_list:print(\n已约满的课程)for cid, name in full_list:print(f编号{cid}名称{name})else:print(\n所有课程均有空位)def show_reservations(reservations: list) - None:打印所有预约操作日志if not reservations:print(暂无预约记录)returnprint( 预约日志按时间顺序 )for log in reservations:act, phone, name, cid, cname, date logprint(f{date}{act} | 会员{name}({phone}) | 课程{cname}({cid}) | 日期{date})def main():主菜单循环menbers {}courses {}reservations []print(健身房 会员与课程预约管理系统)while True:print(str1)choice input(\n请输入功能选项)if choice 1:register_member(menbers)elif choice 2:show_all_members(menbers)elif choice 3:query_member(menbers)elif choice 4:renew_membership(menbers)elif choice 5:add_course(courses)elif choice 6:show_all_courses(courses)elif choice 7:reserve_course(menbers, courses, reservations)elif choice 8:show_statistics(menbers, courses)elif choice 9:show_reservations(reservations)elif choice 10:print(感谢使用系统已退出)breakelse:print(输入无效请输入 1-10 之间的数字)main()