0% found this document useful (0 votes)
79 views10 pages

Ip Python Project

This document describes an IP Python project for a contact book application. It includes screenshots of the interface menu and adding a new contact. It then provides the Python code to connect to a MySQL database, define functions to add, view, search and delete contacts, and a main menu function to run the application. The application allows the user to select from the main menu to perform common contact management tasks.

Uploaded by

cs journey icsi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views10 pages

Ip Python Project

This document describes an IP Python project for a contact book application. It includes screenshots of the interface menu and adding a new contact. It then provides the Python code to connect to a MySQL database, define functions to add, view, search and delete contacts, and a main menu function to run the application. The application allows the user to select from the main menu to perform common contact management tasks.

Uploaded by

cs journey icsi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

IP PYTHON PROJECT

SCREENSHOTS OF INTERFACE :

SCREENSHOT 1:

MENU:
SCREENSHOT 2:

ADD RECORD:
SCREENSHOT 3:

Adding new contacts:


CODING
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: ")

You might also like