Phone Book application

 import pandas as pd


import mysql.connector


mydb = mysql.connector.connect(host="localhost",user="root",password="Siddhu@1102",database="sem3")

mycursor=mydb.cursor()

cur=mydb.cursor()

#print(mydb)

try:

while True:

print("1 Enter into phone book")

print("2 To view contacts")

print("3 To delete a contact")

print("4 to exit ")

i=int(input("enter your option:"))

if i==1:

name=input("Enter name:")

phno=int(input("Enter phone number:"))

if len(str(phno))!=10:

raise Exception("phone bumber can only be 10 digits")

stmt="INSERT INTO phonebook values{} ".format((name,phno))

mycursor.execute(stmt)

mydb.commit()

if i==2:

stmt="select * from phonebook order by name"

col="desc phonebook"

cur.execute(col)

c=cur.fetchall()

cols=[t[0] for t in c]

mycursor.execute(stmt)

rec=mycursor.fetchall()

df=pd.DataFrame(rec,columns=cols)

print(df)

print("\n")

if i==3:

name=input("enter name of the contact to be deleted: ")

stmt="DELETE FROM phonebook WHERE name = '{}'".format(name)

mycursor.execute(stmt)

mydb.commit()

if i==4:

break


except Exception as e:

print(e)


finally:

mydb.close()