Nhiệm vụ của chúng tôi là triển khai một thư mục điện thoại thông minh thu thập dữ liệu liên hệ từ người dùng cho đến khi người dùng nhắc chương trình. Dữ liệu liên hệ đề cập đến tên, số điện thoại, ngày sinh của liên hệ, danh mục mà liên hệ thuộc về [Bạn bè, Gia đình, Công việc, Khác], địa chỉ email. Người dùng có thể nhập càng nhiều dữ liệu càng tốt vào các nhãn dữ liệu được đề cập. Nếu một số nhãn không có dữ liệu, hãy lưu trữ dưới dạng Không có. Tên và số là bắt buộc để tạo liên hệ. Thực hiện các thao tác sau trên thư mục. Chèn, Xóa, Tìm kiếm, Hiển thị
Tiếp cận
Chúng tôi đã sử dụng khái niệm danh sách 2D và triển khai tương tự trong Python3. Có tổng cộng 8 chức năng được sử dụng trong mã này, cụ thể là.
- ban đầu_phonebook[]. Chức năng đầu tiên chạy, nó khởi tạo danh bạ
- thực đơn[]. Nó hiển thị các lựa chọn có sẵn cho người dùng và trả về lựa chọn đã nhập
- add_contact[]. Nó thêm một số liên lạc mới vào thư mục Danh bạ
- loại bỏ_hiện có []. Nó xóa một liên hệ hiện có khỏi thư mục Danh bạ
- xóa hết[]. Nó xóa tất cả các số liên lạc khỏi thư mục Danh bạ
- display_all[]. Nó hiển thị tất cả các số liên lạc từ thư mục Danh bạ
- tìm_kiếm_hiện có[]. Nó sẽ tìm kiếm và hiển thị một liên hệ hiện có trong thư mục Danh bạ
- cảm ơn[]
Giữ trải nghiệm người dùng và giao diện người dùng, chúng tôi đã làm cho mã đơn giản, dễ đọc và tương tác. Bạn có thể hoặc không thể sử dụng tất cả các tính năng chính xác như được mô tả bên dưới. Vui lòng xem qua giải pháp mã
Vui lòng thử chạy mã này trên Python IDLE của bạn vì một số lỗi có thể xảy ra nếu bạn chạy ở đây vì yêu cầu đầu vào của người dùng. Bạn cũng có thể mở trang IDE tại GFG và chạy mã của mình ở đó thay vì chạy trực tiếp từ đoạn mã
trăn3
# importing the module
import
sys
# this function will be the first to run as soon as the main function executes
def
initial_phonebook[]:
rows, cols
=
int
import
0_______1_______1import
0import
3import
4import
5
import
8
sys
0
sys
2_______8_______ sys
4
sys
6sys
7
sys
9 # this function will be the first to run as soon as the main function executes
0# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2# this function will be the first to run as soon as the main function executes
3
# this function will be the first to run as soon as the main function executes
4_______2_______6import
0# this function will be the first to run as soon as the main function executes
7 # this function will be the first to run as soon as the main function executes
8 # this function will be the first to run as soon as the main function executes
9def
0def
1def
2
# this function will be the first to run as soon as the main function executes
4_______2_______6import
0def
6_______4_______7
# this function will be the first to run as soon as the main function executes
4_______2_______6_______1_______0_______5_______1_______4_______7
# this function will be the first to run as soon as the main function executes
4_______5_______4=
sys
4
# this function will be the first to run as soon as the main function executes
4_______2_______9 initial_phonebook[]:
9# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2
2
3
# this function will be the first to run as soon as the main function executes
4_______6_______5
# this function will be the first to run as soon as the main function executes
4_______6_______7
8
9 initial_phonebook[]:
9=
=
rows, cols
3rows, cols
4
rows, cols
5rows, cols
6rows, cols
7_______1_______0import
1import
0=
1=
2
rows, cols
5
rows, cols
5_______8_______5
rows, cols
5=
7
rows, cols
5=
9
rows, cols
5
9 int
2_______8_______=
int
5int
6 int
7
3____9_______9
import
00import
01def
7
3import
04
3
8
9 initial_phonebook[]:
9=
=
def
1rows, cols
4
rows, cols
5rows, cols
6int
import
0import
1import
0import
19=
2
rows, cols
5import
22
rows, cols
5import
24
rows, cols
5import
26
rows, cols
5
8
9 initial_phonebook[]:
9=
=
import
33rows, cols
4
rows, cols
5rows, cols
6rows, cols
7import
0import
1import
0import
41=
2
rows, cols
5import
44
rows, cols
5
9 int
2_______8_______=
int
5int
6 int
7
3int
2=
import
56
3
8
9 initial_phonebook[]:
9=
=
import
63rows, cols
4
rows, cols
5rows, cols
6rows, cols
7_______1_______0import
1import
0import
71_______8_______2
rows, cols
5import
74
rows, cols
5import
76
rows, cols
5import
78
rows, cols
5
9 int
2_______8_______=
int
5int
6 int
7
import
87
rows, cols
5import
44
3int
2=
import
56
8
9 initial_phonebook[]:
9=
=
import
99rows, cols
4
rows, cols
5rows, cols
6
3rows, cols
7import
0_______1_______1import
0sys
08=
2
rows, cols
5import
44
rows, cols
5
9 int
2_______8_______=
sys
17sys
18 int
2=
=
sys
22rows, cols
4
3int
2=
import
56
3
# this function will be the first to run as soon as the main function executes
4_______2_______30
# this function will be the first to run as soon as the main function executes
4_______2_______32
# this function will be the first to run as soon as the main function executes
4_______2_______34
sys
6sys
7
sys
40 sys
2
def
sys
43
sys
45
sys
47
sys
49
sys
6_______1_______0_______2_______53def
7
sys
6import
0sys
58sys
59=
2_______61def
7
sys
6_______1_______0_______2_______53def
7
sys
6_______1_______0_______2_______71def
7
sys
6import
0sys
76def
7
sys
6import
0sys
81def
7
sys
6import
0sys
86def
7
sys
6_______1_______0sys
91def
7
sys
6import
0sys
96def
7
sys
6import
0# this function will be the first to run as soon as the main function executes
01def
7
# this function will be the first to run as soon as the main function executes
04
# this function will be the first to run as soon as the main function executes
06
# this function will be the first to run as soon as the main function executes
08_______8_______ int
import
0_______1_______1import
0# this function will be the first to run as soon as the main function executes
14def
2
sys
40 # this function will be the first to run as soon as the main function executes
08
def
# this function will be the first to run as soon as the main function executes
21
# this function will be the first to run as soon as the main function executes
23
# this function will be the first to run as soon as the main function executes
25
# this function will be the first to run as soon as the main function executes
27_______8_______ sys
4
sys
9 # this function will be the first to run as soon as the main function executes
0# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2_______1_______0# this function will be the first to run as soon as the main function executes
36# this function will be the first to run as soon as the main function executes
37rows, cols
3# this function will be the first to run as soon as the main function executes
39
# this function will be the first to run as soon as the main function executes
4_______6_______9 # this function will be the first to run as soon as the main function executes
0=
=
rows, cols
3_______7_______4
8# this function will be the first to run as soon as the main function executes
48rows, cols
7import
0_______1_______1import
0# this function will be the first to run as soon as the main function executes
53=
2
# this function will be the first to run as soon as the main function executes
4_______6_______9 # this function will be the first to run as soon as the main function executes
0=
=
def
1rows, cols
4
8# this function will be the first to run as soon as the main function executes
48int
import
0import
1import
0# this function will be the first to run as soon as the main function executes
68=
2
# this function will be the first to run as soon as the main function executes
4_______6_______9 # this function will be the first to run as soon as the main function executes
0=
=
import
33_______7_______4
8# this function will be the first to run as soon as the main function executes
48rows, cols
7import
0_______1_______1import
0import
41=
2
# this function will be the first to run as soon as the main function executes
4_______6_______9 # this function will be the first to run as soon as the main function executes
0=
=
import
63rows, cols
4
8# this function will be the first to run as soon as the main function executes
48rows, cols
7_______1_______0_______1_______1import
0import
71_______8_______2
# this function will be the first to run as soon as the main function executes
4_______6_______9 # this function will be the first to run as soon as the main function executes
0=
=
import
99rows, cols
4
8# this function will be the first to run as soon as the main function executes
48
rows, cols
5rows, cols
7import
0_______1_______1import
0sys
08=
2
def
17
def
19
sys
40 def
22
def
def
24
def
26
4_______28_______8_______ rows, cols
7import
0
# this function will be the first to run as soon as the main function executes
4_______1_______1_______1_______0def
35_______4_______2
def
38
initial_phonebook[]:
4=
rows, cols
3
def
45
2_______9 # this function will be the first to run as soon as the main function executes
0# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2import
0# this function will be the first to run as soon as the main function executes
36def
54
# this function will be the first to run as soon as the main function executes
4_______6_______9 def
28_______8__________=
def
60rows, cols
3def
62
8initial_phonebook[]:
4_______4_______0=
def
1
8def
69
8
8sys
6def
73
8def
75
8
8sys
6import
0def
80_______4_______7
8def
83
8def
85
8def
87
8def
89
8
8sys
40 def
22
9 initial_phonebook[]:
4_______8_______=
rows, cols
3rows, cols
4
# this function will be the first to run as soon as the main function executes
4_______5_______02
# this function will be the first to run as soon as the main function executes
4_______5_______04
# this function will be the first to run as soon as the main function executes
4_______2_______6initial_phonebook[]:
07
initial_phonebook[]:
09_______5_______10 initial_phonebook[]:
11 initial_phonebook[]:
12
# this function will be the first to run as soon as the main function executes
4
# this function will be the first to run as soon as the main function executes
4_______2_______40 def
22
def
initial_phonebook[]:
18
initial_phonebook[]:
20
initial_phonebook[]:
22
sys
40 initial_phonebook[]:
25
def
initial_phonebook[]:
27
initial_phonebook[]:
29
# this function will be the first to run as soon as the main function executes
08=
int
import
0_______1_______1initial_phonebook[]:
36
5_______38 initial_phonebook[]:
39initial_phonebook[]:
40_______5_______41initial_phonebook[]:
42initial_phonebook[]:
43initial_phonebook[]:
44initial_phonebook[]:
43initial_phonebook[]:
46initial_phonebook[]:
43initial_phonebook[]:
48
initial_phonebook[]:
50
initial_phonebook[]:
52
initial_phonebook[]:
4=
sys
4
initial_phonebook[]:
59_______8_______ initial_phonebook[]:
40def
1
9 # this function will be the first to run as soon as the main function executes
08=
=
def
1rows, cols
4
initial_phonebook[]:
72
# this function will be the first to run as soon as the main function executes
4_______4_______28=
rows, cols
7_______1_______0
8import
1_______1_______0_______5_______81_______4_______2
# this function will be the first to run as soon as the main function executes
4_______2_______9 # this function will be the first to run as soon as the main function executes
0# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2import
0# this function will be the first to run as soon as the main function executes
36def
54
8
9 def
28_______8_______=
def
60rows, cols
3def
62
rows, cols
5initial_phonebook[]:
59=
# this function will be the first to run as soon as the main function executes
0
rows, cols
5
04
rows, cols
5
07 # this function will be the first to run as soon as the main function executes
08=
=
import
33rows, cols
4
14
# this function will be the first to run as soon as the main function executes
4_______4_______28=
int
import
0
8import
1_______1_______0
23_______4_______2
# this function will be the first to run as soon as the main function executes
4_______2_______9 # this function will be the first to run as soon as the main function executes
0# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2import
0# this function will be the first to run as soon as the main function executes
36def
54
8
9 def
28_______8_______=
def
60def
1def
62
rows, cols
5initial_phonebook[]:
59=
# this function will be the first to run as soon as the main function executes
0
rows, cols
5
04
rows, cols
5
07 # this function will be the first to run as soon as the main function executes
08=
=
import
63rows, cols
4
56
# this function will be the first to run as soon as the main function executes
4_______4_______28=
rows, cols
7_______1_______0import
1
63initial_phonebook[]:
40
65
66
67
# this function will be the first to run as soon as the main function executes
4_______6_______69
# this function will be the first to run as soon as the main function executes
4_______2_______9 # this function will be the first to run as soon as the main function executes
0# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2import
0# this function will be the first to run as soon as the main function executes
36def
54
8
9 def
28_______8_______=
def
60import
33def
62
rows, cols
5initial_phonebook[]:
59=
# this function will be the first to run as soon as the main function executes
0
rows, cols
5
04
rows, cols
5
07 # this function will be the first to run as soon as the main function executes
08=
=
import
99rows, cols
4
rows, cols
01
# this function will be the first to run as soon as the main function executes
4_______4_______28=
rows, cols
7_______1_______0import
1rows, cols
08# this function will be the first to run as soon as the main function executes
1 rows, cols
10initial_phonebook[]:
43rows, cols
12initial_phonebook[]:
43rows, cols
14rows, cols
15 rows, cols
16
8
69
# this function will be the first to run as soon as the main function executes
4_______2_______9 # this function will be the first to run as soon as the main function executes
0# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2import
0# this function will be the first to run as soon as the main function executes
36def
54
8
9 def
28_______8_______=
def
60import
63def
62
rows, cols
5initial_phonebook[]:
59=
# this function will be the first to run as soon as the main function executes
0
rows, cols
5
04
rows, cols
5
07 # this function will be the first to run as soon as the main function executes
08=
=
import
5rows, cols
4
rows, cols
50
# this function will be the first to run as soon as the main function executes
4_______4_______28=
rows, cols
7_______1_______0
8import
1_______1_______0rows, cols
59def
2
# this function will be the first to run as soon as the main function executes
4_______2_______9 # this function will be the first to run as soon as the main function executes
0# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2import
0# this function will be the first to run as soon as the main function executes
36def
54
8
9 def
28_______8_______=
def
60import
99def
62
rows, cols
5initial_phonebook[]:
59=
# this function will be the first to run as soon as the main function executes
0
rows, cols
5
04
# this function will be the first to run as soon as the main function executes
4_______7_______84
# this function will be the first to run as soon as the main function executes
4
rows, cols
87rows, cols
4
rows, cols
90
# this function will be the first to run as soon as the main function executes
4_______2_______6import
0rows, cols
94def
7
# this function will be the first to run as soon as the main function executes
4_______2_______40 initial_phonebook[]:
40def
1
=
01
=
04
=
06
9 initial_phonebook[]:
59=
=
initial_phonebook[]:
40def
1_______7_______4
# this function will be the first to run as soon as the main function executes
4_______2_______40 initial_phonebook[]:
40def
1
# this function will be the first to run as soon as the main function executes
4_______8_______21
rows, cols
87rows, cols
4
# this function will be the first to run as soon as the main function executes
4_______8_______26
# this function will be the first to run as soon as the main function executes
4_______2_______40 initial_phonebook[]:
59
# this function will be the first to run as soon as the main function executes
4_______8_______31
# this function will be the first to run as soon as the main function executes
4_______8_______33
=
34
def
=
36
9 =
39 =
40
=
42
=
44
# this function will be the first to run as soon as the main function executes
4_______2_______6import
0=
48def
7
rows, cols
87rows, cols
4
# this function will be the first to run as soon as the main function executes
4_______2_______9 # this function will be the first to run as soon as the main function executes
0# this function will be the first to run as soon as the main function executes
1 # this function will be the first to run as soon as the main function executes
2import
0# this function will be the first to run as soon as the main function executes
36def
54
8sys
6=
63
def
=
65
=
66
sys
6_______1_______0_______2_______53def
7
sys
6import
0=
75def
7
sys
6import
0=
80def
7
sys
6_______1_______0_______2_______53def
7
int
9_______8_______89def
7
=
91
sys
6import
0_______5_______1def
7
sys
6import
0_______8_______98def
7
sys
6import
0_______9_______02def
7
sys
6import
0_______5_______1def
7
int
08
int
09
int
10=
def
1
def
22_______8_______ int
15
int
16 int
10_______3_______1 import
0_______4_______1int
21import
33int
21import
63int
21import
99int
21import
5int
29