python寫的通訊錄

2021-08-08 22:18:32 字數 2483 閱讀 9673

通訊錄的**如下:
classpeople:

name=''number=0

n=0defsay(self):

print('{}\n\t名字:{}\n\t**號碼:{}'.format(self.n+1,self.name,self.number))

defrevise(self):

number=input('請輸入號碼:')

p=people()

list=

defview():

foriinlist:

i.say()

defadd():

print('現在一共有{}個聯絡人'.format(len(list)-1))

edit(len(list)-1)

defedit(a,b=1):

ct=0

if(b==2):

print('''\t1.名字:{}\n\t2.**號碼:{}'''.format(list[a].name, list[a].number))

ct=int(input('請問你要修改什麼?請輸入對應的序號'))

list[a].n=a

if(b==1

orct==1):

list[a].name=input('請輸入名字:')

if(b==1

orct==2):

list[a].number=input('請輸入**號碼:')

if(b==1):

print('已成功新增!')

else:

print('已成功修改!')

list[a].say()

defrevise():

view()

))-1

edit(a,2)

foriinrange(1,10):

print('''你可以輸入下面的序號以執行對應的操作:1.檢視所有聯絡人2.增加聯絡人3.修改聯絡人4.查詢聯絡人''')

a=int(input())

ifa==1:

view()

ifa==2:

add()

ifa==3:

revise()

反思如下:
在python裡,類也屬於物件,如果要類例項化則應在後面加()
classp:

name=''p=p()

list=

list[0].name='hhh'list[1].name='haha'print(list[0].name)

print(list[1].name)

classp:

name=''p=p()

list=

list[0].name='hhh'list[1].name='hahahha'print(list[0].name)

print(list[1].name)

python 寫的通訊錄

儲存為 book.py 執行命令 python book.py f add n name1 a address1 新增 使用者,位址 python book.py f insert n name1 a address1 新增 根據 使用者,位址 python book.py f select n n...

單鏈表寫通訊錄

單鏈表實現通訊錄,增加,刪除,更改乙個聯絡人等功能。其中增加了乙個記憶體池功能,用於對廢棄記憶體的 和利用。include include include define max 1024 void addperson struct presonlist node 新增乙個聯絡人 void displ...

鍊錶寫的通訊錄

include include include include struct node typedef struct node node typedef struct node link void create link head void insert link head,link new nod...