-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop_contacts.py
More file actions
118 lines (81 loc) · 2.39 KB
/
Copy pathoop_contacts.py
File metadata and controls
118 lines (81 loc) · 2.39 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
class Contact:
def __init__(self, name, phone, email):
self.name = name
self.phone = phone
self.email = email
def show(self):
print("----------------")
print("Name :", self.name)
print("Phone:", self.phone)
print("Email:", self.email)
print("----------------")
contacts = []
def dashboard():
print("======Phone book======")
def welcome():
print("Press 1 to Add Contact")
print("Press 2 to Remove Contact")
print("Press 3 to Show Contact")
print("Press 4 to Search Contact")
print("Press 0 to Exit!")
def add_contact():
name = input("Enter name: ")
phone = input("Enter phone: ")
email = input("Enter email: ")
new_contact = Contact(name, phone, email)
contacts.append(new_contact)
print("Contact added successfully")
def show_contact():
if len(contacts) == 0:
print("No contact found")
else:
for c in contacts:
c.show()
def search_contact():
number = input("Enter the number you want to search: ")
found = False
for c in contacts:
if number == c.phone:
print("\nContact Found!")
c.show()
found = True
break
if not found:
print("Contact not found!")
def remove_contact():
number = input("Enter the number you want to delete: ")
found = False
for c in contacts:
if number == c.phone:
c.show()
contacts.remove(c)
print("\nContact Removed.")
found = True
break
if not found:
print("Contact not found!")
choices = [0, 1, 2, 3, 4]
def choose():
while True:
dashboard()
welcome()
try:
choice = int(input("Press Any number: "))
except ValueError:
print("Please enter a valid number!\n")
continue
if choice not in choices:
print("Invalid choice!\n")
continue
if choice == 1:
add_contact()
elif choice == 2:
remove_contact()
elif choice == 3:
show_contact()
elif choice == 4:
search_contact()
elif choice == 0:
print("Thankyou!")
break
choose()