#--coding:utf-8--
#通讯录
def select():
print(‘请选择以下功能:\n’
‘1.添加联系人:包括(姓名\性别\年龄\联系电话\家庭住址)\n’
‘2.显示联系人\n’
‘3.删除联系人\n’
‘4.查找联系人\n’
‘5.修改联系人\n’
‘6.清空联系人\n’
‘7.退出联系人\n’)
#number=int(input(‘please input a number:\n’))
#return number
class Person:
def init(self,name,sex,age,tel,address):
self.name=name
self.sex=sex
self.age=age
self.tel=tel
self.address=address
def setname(self,name):
self.name=name
def setsex(self,sex):
self.sex=sex
def setage(self,age):
self.age=age
def settel(self,tel):
self.tel=tel
def setaddress(self,address):
self.address=address
def printinfo(self):
print('name:{} sex:{} age:{} tel:{} address:{}'.format(self.name, self.sex, self.age, self.tel, self.address))
#print('name:'+self.name+' sex:'+self.sex+' age:'+self.age+' tel:'+self.tel+' address:'+self.address)
#print('name:{},sex:{},age:{},tel:{},address:{}'.format(self.name,self.sex,self.age,self.tel,self.address))
def addinfo(info):
print(‘请输入添加的信息\n’)
name = input(‘please input name:\n’)
sex = input(‘please input sex:\n’)
age = input(‘please input age:\n’)
tel = input(‘please input tel:\n’)
address = input(‘please input address:\n’)
per=Person(name,sex,age,tel,address)
info[name]=per
print(‘信息添加成功\n’)
def showinfo(info):
for key in info:
info[key].printinfo()
#printinfo(info[key])
def deleteinfo(info):
deletename = input(‘请输入要删除的联系人名称\n’)
#if deletename in info[‘name’]:
if deletename in info.keys():
del info[deletename]
print(‘删除成功(打到蓝猫成功)’)
else:
print(‘未查询到联系人信息\n’)
return
def findinfo(info):
findname=input(‘请输入要查找的联系人名称:\n’)
if findname in info.keys():
#print(info[findname])
info[findname].printinfo()
else:
print(‘未查询到联系人信息’)
return
def changeinfo(info):
changename = input(‘请输入要修改的联系人名称:\n’)
if changename in info.keys():
#name = input(‘please input name:\n’)
sex = input(‘please input sex:\n’)
age = input(‘please input age:\n’)
tel = input(‘please input tel:\n’)
address = input(‘please input address:\n’)
per = Person(changename, sex, age, tel, address)
info[changename] = per
print(‘修改成功’)
else:
print(‘未查询到要修改的名称:\n’)
return
def clearall(info):
info.clear()
print(‘清空成功’)
def main():
select()
info={}
while True:
select()
number = int(input(‘please input a number:\n’))
if number1:
addinfo(info)
#n=input(‘是否继续输入信息?(y/n)\n’)
#if n’n’:
#continue
elif number2:
showinfo(info)
elif number3:
deleteinfo(info)
elif number4:
findinfo(info)
elif number5:
changeinfo(info)
elif number6:
clearall(info)
elif number7:
exit()
#break
else:
print(‘输入错误请重新输入’)
if name==‘main’:
main()