forked from kal179/Beginners_Python_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhonebook.py
More file actions
224 lines (158 loc) · 4.74 KB
/
Phonebook.py
File metadata and controls
224 lines (158 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
phone = {}
class Phonebook:
def __init__ ( self, fname, lname, phone_number, email, address ):
self.fname = fname
self.lname = lname
self.phone_number = phone_number
self.email = email
self.address = address
def view_info( self ):
print( "Name : {} {}".format( self.fname, self.lname ) )
print( "Phone number : {}".format( self.phone_number ) )
print( "Email : {}".format( self.email ) )
print( "Address : {}".format( self.address ) )
def show_number( self ):
return( "Phone number : {}".format( self.phone_number ) )
def show_email ( self ):
return( "Email : {}".format( self.email ) )
def add():
while (True):
get_fname = str(input( "First name : " ))
get_lname = str(input( "Last name : " ))
get_phone_number = int(input( "Phone number : " ))
get_email = str(input( "Email address : " ))
get_address = str(input( "Home address : " ))
full_name = get_fname + " " + get_lname
phone[full_name] = Phonebook( get_fname, get_lname, get_phone_number, get_email, get_address )
more = str(input("Do you want to add more [Y/n] : "))
if more.strip() == "Y":
print(" ")
continue
else:
print(" ")
break
def update():
# still working here
pass
def view_all():
while (True):
name = str(input( "Full name : " ))
if name in phone.keys():
print(phone[name].view_info())
else:
print("The name you entered does not exist.Try again")
more = str(input("Do you want to view more [Y/n] : "))
if more.strip() == "Y":
print(" ")
continue
else:
print(" ")
break
def number_contacts():
num_of_contacts = 0
for i in phone.keys():
num_of_contacts += 1
return("Total number of contacts : {}".format(num_of_contacts))
def view_number():
while (True):
name = str(input( "Full name : " ))
if name in phone.keys():
print(phone[name].view_number())
else:
print("The name you entered does not exist.Try again")
more = str(input("Do you want to view more [Y/n] : "))
if more.strip() == "Y":
print(" ")
continue
else:
print(" ")
break
def view_email():
while (True):
name = str(input( "Full name : " ))
if name in phone.keys():
print(phone[name].view_email())
else:
print("The name you entered does not exist.Try again")
more = str(input("Do you want to view more [Y/n] : "))
if more.strip() == "Y":
print(" ")
continue
else:
print(" ")
break
def view_names():
print("All contacts : ")
for i in phone.keys():
print(" {}".format(i))
def delete():
while (True):
if len(phone.keys()) == 0:
print("The contacts list is empty.")
break
name = str(input( "Full name : " ))
if name in phone.keys():
del phone[name]
print("Contact deleted successfully.")
else:
print("The name you entered does not exist.Try again")
more = str(input("Do you want to delete more [Y/n] : "))
if more.strip() == "Y":
print(" ")
continue
else:
print(" ")
break
print("========================Program Started========================")
print("Hello,")
while (True):
start_or_end = str(input( "Start or End : " ))
if start_or_end.strip() == "Start" :
op = str(input( "Add or Update or Delete or View : " ))
if op.strip() == "Add":
print(add())
print(" ")
continue
elif op.strip() == "Update":
print(update())
print(" ")
continue
elif op.strip() == "Delete":
print(delete())
print(" ")
continue
elif op.strip() == "View":
view_op = str(input("View all or View number or View email or View names: "))
if view_op.strip() in [ "View all", "view all", "view All", "View all", "all" ]:
print(view_all())
print(" ")
continue
elif view_op.strip() in [ "View number", "view number", "view Number", "View Number", "number" ]:
print(view_number())
print(" ")
continue
elif view_op.strip() in [ "View email", "view email", "view Email", "View Email", "email" ]:
print(view_email())
print(" ")
continue
elif view_op.strip() in [ "View names", "view names", "view Names", "View Names", "names" ]:
print(view_names())
print(" ")
print(number_contacts())
print(" ")
continue
else:
print("Invalid Input for View menu.")
print(" ")
continue
else:
print("Invalid Input. Try again!")
print(" ")
continue
elif start_or_end.strip() == "End":
print("=========================Program Ended=========================")
break
else:
print("Invalid Input. Try again!")
print(" ")
continue