class Friend:
def __init__(self):
self.friend_li = {}
# 实例方法
def welcome(self):
print("欢迎来到好友管理系统")
print("1.添加好友")
print("2.删除好友")
print("3.展示好友")
print("4.好友备注")
print("5.退出系统")
while True:
choice = input("请输入你的选择:")
if choice == "1":
self.add_friend()
elif choice == "2":
self.del_friend()
elif choice == "3":
self.show_friend()
elif choice == "4":
self.friend_remark()
elif choice == "5":
self.exit_friend()
else:
print("输入有误,请重新输入!")
# 添加好友
def add_friend(self):
name = input("请输入好友姓名:")
if name in self.friend_li:
print("该好友已存在!")
else:
self.friend_li[name] = "无备注"
print("添加成功!")
# 删除好友
def del_friend(self):
name = input("请输入要删除的好友姓名:")
if name in self.friend_li:
self.friend_li.pop(name)
print("删除成功!")
else:
print("该好友不存在!")
# 展示好友
def show_friend(self):
for i in self.friend_li:
print("名称:", i, "备注:", self.friend_li[i])
# 退出系统
@staticmethod
def exit_friend():
print("退出系统!")
exit(0)
# 好友备注
def friend_remark(self):
name = input("请输入好友姓名:")
if name in self.friend_li:
remark = input("请输入好友备注:")
self.friend_li[name] = remark
print("修改成功!")
else:
print("该好友不存在!")
friend = Friend()
friend.welcome()
© 版权声明
THE END
暂无评论内容