Skip to content

Commit ceb7bab

Browse files
[shubham] Add: This python file contains operations of address book problem.
1 parent b526519 commit ceb7bab

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

AddressBook_Service.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# class Contact with user inputs
2+
class Contact:
3+
def __init__(self, first_name,last_name,address,city,state,zip,phone_number, email):
4+
self.first_name = first_name
5+
self.last_name = last_name
6+
self.address = address
7+
self.city = city
8+
self.state = state
9+
self.zip = zip
10+
self.phone_number = phone_number
11+
self.email = email
12+
13+
14+
def __str__(self):
15+
return (f" First name: {self.first_name}\n Last Name: {self.last_name}\n Address: {self.address}\n Name: {self.city}\n Zip: {self.zip}\n Phone-Number: {self.phone_number}\n Email: {self.email}")
16+
17+
18+
# Addressbook Operations
19+
class AddressBook:
20+
def __init__(self):
21+
self.contacts = []
22+
23+
def add_contact():
24+
"""
25+
Description :
26+
This function takes inputs from user, sents it to class contact through object and prints the contact result.
27+
Parameters :
28+
none
29+
Returns :
30+
contact - contact object __str__ function which overides the object.
31+
"""
32+
first_name =input("Enter first name: ")
33+
second_name = input("Enter second name: ")
34+
address =input("Enter address: ")
35+
city =input("Enter city: ")
36+
state =input("Enter state: ")
37+
zip =int(input("Enter zip: "))
38+
phone_number =int(input("Enter phone number: "))
39+
email_id = input("Enter email id: ")
40+
41+
contact = Contact(first_name,second_name,address,city,state,zip,phone_number,email_id)
42+
print("Contact Added Succesfully")
43+
44+
return contact
45+
46+
47+
def display_contact(contact):
48+
"""
49+
Description :
50+
This function prints the object of class contact.
51+
Parameters :
52+
contact : return object from add_contact function.
53+
Returns:
54+
none
55+
prints contact object
56+
"""
57+
print(contact)
58+
59+
60+
61+

0 commit comments

Comments
 (0)