-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddressbook.py
More file actions
82 lines (72 loc) · 2.67 KB
/
addressbook.py
File metadata and controls
82 lines (72 loc) · 2.67 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
"""
This program is a contact addressbook that stores it in a text file
"""
import sys
ns=0
dd = open('contactbook.txt', 'r')
def adressbook(ns,dd):
for line in dd:
ns=ns+1
print(" This addressbook stores names and phone number")
print(" ")
print("*****************************************************")
contacts=[ ]
try:
try:
number= int(input(" How many contacts do you want to register? >>"))
except (ValueError):
print ("It requires an integer")
print(" ")
for no in range(number):
ns+=1
name= input("Please insert the name >>")
phoneno=input("Please insert the phone number >>")
contact = "{:3d} Name: {:20} Phone Number: {:35}".format(ns,name,phoneno)
# contact = str(ns) + " "+ "Name: "+name + " : "+ "Phone Number: "+phoneno
contacts.append(contact)
print (contact)
print (" Inserted Sucessfully")
print(" ")
print("*****************************************************")
print("These are the contacts you added to the addressbook")
print(" ")
for con in contacts:
print (con)
print(" ")
print("*****************************************************")
print(" ")
responseA= input("Are the contacts correct? y or n >>").lower()
if responseA=="y":
for con in contacts:
address = open("contactbook.txt","a")
address.write(con + '\n')
print(" ")
print("*****************************************************")
print (" Successfully added to the addressbook")
print("*****************************************************")
print(" ")
elif responseA =="n":
responseB= input("Do you want to start again ? y or n >>").lower()
if responseB=="y":
adressbook(ns,dd)
elif responseB=="n":
print(" ")
print("*****************************************************")
print (" Nothing was saved to the addressbook")
print("*****************************************************")
print(" ")
exit
else:
exit
else:
exit
except ValueError:
print("Check your input")
retry= input("Do you want to start again? y or n >>").lower()
if retry=="y" :
adressbook()
elif retry=="n" :
exit
else:
exit
adressbook(ns,dd)