Contact Book Python Project

0
2447
Contact Book Python Project

This program implements the Contact Book of mobile using Python and MySQL connectivity.Contact Book Python Project

In this Program, we have 4 options for the user ” To add New contact”, “To view Contact”, “To search Contact”, “To Delete Contact” You have to choose the Options to form above as user requirement

IF you select ” To add New contact ” You will get a form and fill the form “Mobile_no”,”Name”,”Address”,”Email”.

IF you select “To search Contact” You will get again four criteria and search it by name, Mobile No, Address, Email

Also Read:- Instant Messaging System Python Project

Contact Book Python Project [Source code]

import os
import platform
import mysql.connector
import pandas as pd
mydb=mysql.connector.connect(host="localhost",user="root",passwd="arun",database="contact")

mycursor=mydb.cursor()

def add_contact():
L=[]
mobile_no=input("Enter Moobile number(10 Digits): ")
L.append(mobile_no)
name=input("Enter the Name : ")
L.append(name)
address=input("Enter address : ")
L.append(address)
email=input("Enter the email : ")
L.append(email)
cont=(L)
sql="insert into contact_book(mobile_no,name,address,email) values (%s,%s,%s,%s)"
mycursor.execute(sql,cont)
mydb.commit()

def view_contact():
print("Select the search criteria : ")
print("1. Mobile_no")
print("2. Name")

print("3. Address")
print("4. email")
print("5. All contacts")
ch=int(input("Enter the choice : "))
if (ch==1):
s=input("Enter mobile Nummber : ")
rl=(s,)
sql="select * from contact_book where mobile_no=%s"
mycursor.execute(sql,rl)
elif (ch==2):
nm=input("Enter Name : ")
rl=(nm,)
sql="select * from contact_book where name='%s';"%nm
mycursor.execute(sql)
elif (ch==3):
s=input("Enter address : ")
rl=(s,)
sql="select * from contact_book where address=%s;"
mycursor.execute(sql,rl)
elif (ch==4):
s=input("Enter email : ")
rl=(s,)
sql="select * from contact_book where email=%s;"
mycursor.execute(sql,rl)
elif (ch==5):
sql="select * from contact_book;"
mycursor.execute(sql)
res=mycursor.fetchall()
print("The contact details are as follows : ")

print("(mobile_no , name , address ,email )")
for x in res:
print(x)

def del_contact():
name=input("Enter the name to be deleted : ")
rl=(name,)
sql="delete from contact_book where name=%s"
mycursor.execute(sql,rl)
mydb.commit()

def Main_Menu():
print("Enter 1 : TO ADD NEW CONTACT")
print("Enter 2 : TO VIEW CONTACT ")
print("Enter 3 : TO SEARCH CONTACT ")
print("Enter 4 : TO DELETE CONTACT")
try: #Using Exceptions For Validation
userInput = int(input("Please Select An Above Option: ")) #Will Take Input From User
except ValueError:
exit("\nHy! That's Not A Number") #Error Message

else:
print("\n") #Print New Line
if(userInput==1):
add_contact()
elif (userInput==2):
view_contact()
elif (userInput==3):

search_contact()
elif (userInput==4):
del_contact()
else:
print("Enter correct choice. . . ")

Main_Menu()
ch = input("\nwant to continue Y/N: ")
while(ch == 'Y' or ch=='y'):
print(os.system('cls'))
Main_Menu()
ch = input("\nwant To Run Again Y/N: ")

Output Screen

Contact Book Python Project
Contact Book Python Project

Along these lines, I really want to believe that you preferred the article and you would have found the substance of the article valuable and supportive for you. Share this article in your coding networks so that more individuals can exploit the substance. In case of any doubt feel free to ask me on social media

Enjoy Coding!

LEAVE A REPLY

Please enter your comment!
Please enter your name here