-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhoneBook.py
71 lines (55 loc) · 1.44 KB
/
PhoneBook.py
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
import os
# choose desired Path
Path = ""
def IsValid():
if not os.path.exists(Path):
f = open(Path, "w+")
f.write("")
def add(name , number):
IsValid()
f = open(Path, "a+")
Phone = name + "_" + number + "\n"
f.write(Phone)
f.close()
def Search(name):
IsValid()
f = open(Path , "r")
for Line in f.readlines():
if name == Line.split("_")[0]:
print(name + " : " + Line.split("_")[1])
f.close()
def Delete(name):
IsValid()
f = open(Path , "r")
Save = ""
for Line in f.readlines():
if not name == Line.split("_")[0]:
Save += Line
f.close()
f = open(Path , "w")
f.write(Save)
f.close()
def Show_Info():
IsValid()
f = open(Path , "r")
DataBase = ""
DataBase = f.read()
f.close()
print(DataBase)
choice = 1
while choice != 0 :
print("Choose your desired choice\n 1.Add User\n 2.Search Phone \n 3.Delete Phone\n 4.Show numbers\n 0.Exit\n")
choice = int(input())
os.system('cls')
if choice == 1:
Name = input("Enter The Name :")
Number = input("Enter The Number :")
add(Name , Number)
elif choice == 2:
Name = input("Enter The Name :")
Search(Name)
elif choice == 3:
Name = input("Enter The Name :")
Delete(Name)
elif choice == 4:
Show_Info()