class ContactList:
def init(self):
self.arr = []
def is_full(self):
return self.num == self.capacity
def add_contact(self, person):
self.arr.append(person)
self.save_contacts()
def is_empty(self):
if not self.arr:
print("当前联系人列表为空!")
def remove_contact(self, name):
person = self.find_contact(name)
if person:
self.arr.remove(person)
self.save_contacts()
print("删除成功!")
self.is_empty()
else:
print("此联系人不存在!")
def show_contacts(self):
print('通讯录:')
for person in self.arr:
print(person)
self.is_empty()
def find_contact(self, name):
for person in self.arr:
if person.name == name:
return person
return None
def modify_contact(self, old_name, new_info):
person = self.find_contact(old_name)
if person:
person.name = new_info.name
person.gender = new_info.gender
person.age = new_info.age
person.telephone = new_info.telephone
person.address = new_info.address
self.save_contacts()
print("修改成功!\n ", person)
else:
print("此联系人不存在!")
def save_contacts(self, filename="contacts.csv"):
with open(filename, 'w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerow(['姓名', '性别', '年龄', '电话', '住址'])
for person in self.arr:
writer.writerow([person.name, person.gender, person.age, person.telephone, person.address])
def load_contacts(self, filename="contacts.csv"):
if not os.path.isfile(filename):
with open(filename, 'w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerow(['姓名', '性别', '年龄', '电话', '住址'])
with open(filename, 'r', newline='', encoding='utf-8') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
if len(row) == 5:
name, gender, age, telephone, address = row
self.add_contact(PersonInformation(name, gender, age, telephone, address))
else:
print(f"跳过不完整的联系人记录: {row}")
def menu(contact_list):
print()
print(““)
print(” 1、增加联系人 2、删除联系人 “)
print(” 3、查找联系人 4、修改联系人 “)
print(” 5、展示联系人 0、退出通讯录 “)
print(””)
def main():
contact_list = ContactList()
contact_list.load_contacts()
while True:
menu(contact_list)
name, gender, age, telephone, address = [“”]5
input_choice = input(“请输入您的选择:”)
if input_choice == ‘1’:
while len(name)<2:
name = input(“请输入您要添加的联系人的姓名:\n”)
if contact_list.find_contact(name):
print(f’此姓名[{name}]已存在!')
break
while gender not in (‘男’,‘女’,‘1’,‘0’):
gender = input(“请输入性别(1-男, 0-女):\n”)
if gender==‘1’: gender = ‘男’
elif gender==‘0’: gender = ‘女’
while not age.isnumeric():
age = input(“请输入年龄:\n”)
while telephone is None or len(telephone)!=11 or not telephone.startswith(‘1’):
telephone = input(“请输入手机号:\n”)
while len(address)<6:
address = input(“请输入住址(字数不少于6):\n”)
contact_list.add_contact(PersonInformation(name, gender, age, telephone, address))
print(“联系人添加成功!”)
elif input_choice == ‘2’:
name = input(“请输入您要删除的联系人的名字:\n”)
contact_list.remove_contact(name)
elif input_choice == ‘3’:
name = input(“请输入您要查找的联系人的名字:\n”)
person = contact_list.find_contact(name)
print(person if person else “此联系人不存在!”)
elif input_choice == ‘4’:
old_name = input(“请输入您要修改的联系人的名字:\n”)
new_info = PersonInformation(([“”]*5))
person = contact_list.find_contact(old_name)
if person:
print('待修改联系人:(直接回车保留原字段)\n ‘, person)
while len(new_info.name)<2:
new_info.name = input(“请输入新的名字:\n”)
if new_info.name==“”:
new_info.name = person.name
elif contact_list.find_contact(name):
print(f’此姓名[{name}]已存在,退出修改!’)
break
while new_info.gender not in (‘男’,‘女’,‘1’,‘0’):
new_info.gender = input(“请输入性别(1-男, 0-女):\n”)
if new_info.gender==‘1’: new_info.gender = ‘男’
elif new_info.gender==‘0’: new_info.gender = ‘女’
elif new_info.gender==“”: new_info.gender = person.gender
while not new_info.age.isnumeric():
new_info.age = input(“请输入年龄:\n”)
if new_info.age==“”: new_info.age = person.age
while len(new_info.telephone)!=11 or not new_info.telephone.startswith(‘1’):
new_info.telephone = input(“请输入新的手机号:\n”)
if new_info.telephone==“”: new_info.telephone = person.telephone
while len(new_info.address)<6:
new_info.address = input(“请输入新的住址(字数不少于6):\n”)
if new_info.address==“”: new_info.address = person.address
contact_list.modify_contact(old_name, new_info)
elif input_choice == ‘5’:
contact_list.show_contacts()
elif input_choice == ‘0’:
print(“成功退出通讯录!”)
break
else:
print(“输入错误,请重新选择!”)
if name == “main”:
main()
### 运行示例
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:5
通讯录:
当前联系人列表为空!
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:1
请输入您要添加的联系人的姓名:
Hann
请输入性别(1-男, 0-女):
1
请输入年龄:
51
请输入手机号:
13962600000
请输入住址(字数不少于6):
江苏省昆山市
联系人添加成功!
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:5
通讯录:
名字: Hann, 性别: 男, 年龄: 51, 电话: 13962600000, 住址: 江苏省昆山市
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:1
请输入您要添加的联系人的姓名:
Hann
此姓名[Hann]已存在!
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:1
请输入您要添加的联系人的姓名:
YangCheng
请输入性别(1-男, 0-女):
1
请输入年龄:
22
请输入手机号:
13962611111
请输入住址(字数不少于6):
江苏省昆山市
联系人添加成功!
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:5
通讯录:
名字: Hann, 性别: 男, 年龄: 51, 电话: 13962600000, 住址: 江苏省昆山市
名字: YangCheng, 性别: 男, 年龄: 22, 电话: 13962611111, 住址: 江苏省昆山市
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:4
请输入您要修改的联系人的名字:
Hann
待修改联系人:(直接回车保留原字段)
名字: Hann, 性别: 男, 年龄: 51, 电话: 13962600000, 住址: 江苏省昆山市
请输入新的名字:
HannYang
请输入性别(1-男, 0-女):
请输入年龄:
请输入新的手机号:
请输入新的住址(字数不少于6):
修改成功!
名字: HannYang, 性别: 男, 年龄: 51, 电话: 13962600000, 住址: 江苏省昆山市
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:5
通讯录:
名字: HannYang, 性别: 男, 年龄: 51, 电话: 13962600000, 住址: 江苏省昆山市
名字: YangCheng, 性别: 男, 年龄: 22, 电话: 13962611111, 住址: 江苏省昆山市
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:3
请输入您要查找的联系人的名字:
hannyang
此联系人不存在!
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:3
请输入您要查找的联系人的名字:
HannYang
名字: HannYang, 性别: 男, 年龄: 51, 电话: 13962600000, 住址: 江苏省昆山市
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:2
请输入您要删除的联系人的名字:
hann
此联系人不存在!
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:2
请输入您要删除的联系人的名字:
HannYang
删除成功!
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
\*\* 1、增加联系人 2、删除联系人 \*\*
\*\* 3、查找联系人 4、修改联系人 \*\*
\*\* 5、展示联系人 0、退出通讯录 \*\*
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
请输入您的选择:5
通讯录:
名字: YangCheng, 性别: 男, 年龄: 22, 电话: 13962611111, 住址: 江苏省昆山市
### 给大家的福利
**零基础入门**
对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。
![](https://img-blog.csdnimg.cn/img_convert/95608e9062782d28f4f04f821405d99a.png)
同时每个成长路线对应的板块都有配套的视频提供:
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/a91b9e8100834e9291cfcf1695d8cd42.png#pic_center)
因篇幅有限,仅展示部分资料
网络安全面试题
![](https://img-blog.csdnimg.cn/img_convert/80674985176a4889f7bb130756893764.png)
绿盟护网行动
![](https://img-blog.csdnimg.cn/img_convert/9f3395407120bb0e1b5bf17bb6b6c743.png)
还有大家最喜欢的黑客技术
![](https://img-blog.csdnimg.cn/img_convert/5912337446dee53639406fead3d3f03c.jpeg)
**网络安全源码合集+工具包**
![](https://img-blog.csdnimg.cn/img_convert/5072ce807750c7ec721c2501c29cb7d5.png)
![](https://img-blog.csdnimg.cn/img_convert/4a5f4281817dc4613353c120c9543810.png)
**所有资料共282G**,朋友们如果有需要全套《网络安全入门+黑客进阶学习资源包》,可以扫描下方二维码领取(如遇扫码问题,可以在评论区留言领取哦)~
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化资料的朋友,可以点击这里获取](https://bbs.csdn.net/topics/618540462)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**