Python简单会员管理系统
时间: 2024-04-10 09:25:45 浏览: 99
Python项目开发实战_制作会员管理系统_编程案例解析实例详解课程教程.pdf
5星 · 资源好评率100%
Python简单会员管理系统是一个用Python编写的程序,用于管理会员信息和相关操作。以下是一个简单的Python会员管理系统的实现:
1. 创建会员类:
- 属性:姓名、年龄、性别、手机号码
- 方法:获取会员信息、修改会员信息
2. 创建会员管理系统类:
- 属性:会员列表
- 方法:添加会员、删除会员、查找会员、显示所有会员
3. 实现具体功能:
- 添加会员:向会员列表中添加新的会员对象
- 删除会员:根据姓名或手机号码从会员列表中删除对应的会员对象
- 查找会员:根据姓名或手机号码在会员列表中查找对应的会员对象并返回
- 显示所有会员:遍历会员列表,逐个输出会员信息
示例代码如下:
```python
class Member:
def __init__(self, name, age, gender, phone):
self.name = name
self.age = age
self.gender = gender
self.phone = phone
def get_info(self):
return f"姓名:{self.name},年龄:{self.age},性别:{self.gender},手机号码:{self.phone}"
def modify_info(self, name, age, gender, phone):
self.name = name
self.age = age
self.gender = gender
self.phone = phone
class MemberManagementSystem:
def __init__(self):
self.members = []
def add_member(self, member):
self.members.append(member)
def delete_member(self, keyword):
for member in self.members:
if keyword in [member.name, member.phone]:
self.members.remove(member)
def find_member(self, keyword):
for member in self.members:
if keyword in [member.name, member.phone]:
return member
return None
def show_all_members(self):
for member in self.members:
print(member.get_info())
# 创建会员管理系统对象
system = MemberManagementSystem()
# 添加会员
member1 = Member("张三", 25, "男", "13812345678")
system.add_member(member1)
# 删除会员
system.delete_member("张三")
# 查找会员
member2 = Member("李四", 30, "女", "13987654321")
system.add_member(member2)
found_member = system.find_member("李四")
if found_member:
print(found_member.get_info())
else:
print("未找到该会员")
# 显示所有会员
system.show_all_members()
```
阅读全文