Sie sind auf Seite 1von 27

program

import mysql.connector as msql

con=msql.connect(host="localhost",user="root",passwd="mysql",database="shelly")

mycursor=con.cursor()

def add_record():

sno=int(input("enter serial no. :"))

name=input("student name :")

admn=int(input("admission no. of student :"))

lclass=input("class of student :")

book_name=input("book issued by the student :")

author_name=input("author of the book issued :")

book_id=input("id of book :")

date_of_issue=input("date when book is issued :")

cmd="insert into library


(sno,name,admn,class,book_name,author_name,book_id,date_of_issue)\

values({},'{}',{},'{}','{}','{}','{}','{}')".format(sno,name,admn,lclass,book_name,author_name,book_i
d,date_of_issue)

mycursor.execute(cmd)
con.commit()

def modify_record():

sno=int(input("enter serial no. :"))

cmd="select * from library where sno={}".format(sno)

mycursor.execute(cmd)

row=mycursor.fetchone()

if row is None:

print("error:no record with given serial no. ")

return

print("the current values are :")

print("name =",row[1])

print("admn =",row[2])

print("class =",row[3])

print("book_name =",row[4])
print("author_name =",row[5])

print("book_id =",row[6])

print("date_of_issue =",row[7])

print("enter new values :")

sno=int(input("enter serial no. :"))

name=input("student name :")

admn=int(input("admission no. of student :"))

lclass=input("class of student :")

book_name=input("book issued by the student :")

author_name=input("author of the book issued :")

book_id=input("id of book :")

date_of_issue=input("date when book is issued :")

cmd="update library set


name='{}',admn={},class='{}',book_name='{}',author_name='{}',book_id='{}',date_of_issue='{}'
where sno={}".\

format(name,admn,lclass,book_name,author_name,book_id,date_of_issue,sno)

mycursor.execute(cmd)

con.commit()

def delete_record():
sno=int(input("enter serial no. :"))

cmd="select * from library where sno={}".format(sno)

mycursor.execute(cmd)

row=mycursor.fetchone()

if row is none:

print("error: no record with given serial no. ")

return

print("the current values are :")

print("name =",row[1])

print("admn =",row[2])

print("class =",row[3])

print("book_name =",row[4])

print("author_name =",row[5])

print("book_id =",row[6])

print("date_of_issue =",row[7])

q=input("are you sure to delete Y/N")

if q=="y" or q=="Y":
cmd="delete from library where sno ={}".format(sno)

mycursor.execute(cmd)

con.commit()

def show_all_record():

mycursor.execute("select * from library")

print("sno \t name \t admn \t class \t book_name \t author_name \t book_id \t


date_of_issue")

for row in mycursor.fetchall():

print(row[0],"\t",row[1],"\t",row[2],"\t",row[3],"\t",row[4],"\t",row[5],"\t",row[6],"\t",row[7],se
p="\t")

while True:

print("1.insert record")

print("2.modify record")

print("3.delete record")

print("4.show all records")

print("5.exit")
choice=int(input("what you want to do(1-5):"))

if choice==1:

add_record()

if choice==2:

modify_record()

if choice==3:

delete_record()

elif choice==4:

show_all_record()

else:

con.close()

break

output: 
1.insert record

2.modify record

3.delete record

4.show all records

5.exit
what you want to do(1-5):4

sno name admn class book_name author_name book_id


date_of_issue

1 shelly 8472 xii-a


you can win shiv khera 1234
2019-09-09

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :2

student name :simran

admission no. of student :8473

class of student :xii-a

book issued by the student :dept frr u

author of the book issued :zac bessonette

id of book :1235

date when book is issued :2019-08-08

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records


5.exit

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :3

student name :sita

admission no. of student :8474

class of student :xii-b

book issued by the student :your money

author of the book issued :jd roth

id of book :1255

date when book is issued :2019-09-05

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1


enter serial no. :4

student name :ram

admission no. of student :7888

class of student :xii-c

book issued by the student :deep water

author of the book issued :cal newport

id of book :4567

date when book is issued :2019-07-07

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :4

student name :reena

admission no. of student :8455

class of student :xi-d

book issued by the student :5am club

author of the book issued :rubin sharma

id of book :4589

date when book is issued :2019-05-05

>>>
>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :5

student name :janvi

admission no. of student :8888

class of student :x-a

book issued by the student :personal mba

author of the book issued :josh kaujman

id of book :5643

date when book is issued :2019-09-07

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):4


sno name admn class book_name author_name book_id
date_of_issue

4 ram 7888 xii-c


deep water cal newport 4567
2019-07-07

4 reena 8455 xi-d


5am club rubin sharma 4589
2019-05-05

1 shelly 8472 xii-a


you can win shiv khera 1234
2019-09-09

2 simran 8473 xii-a


dept frr u zac bessonette 1235
2019-08-08

3 sita 8474 xii-b


your money jd roth 1255 2019-09-05

5 janvi 8888 x-a


personal mba josh kaujman 5643
2019-09-07

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :6

student name :rohan

admission no. of student :8898

class of student :ix-c

book issued by the student :make good art


author of the book issued :neil gaiman

id of book :2367

date when book is issued :2019-09-07

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :7

student name :seema

admission no. of student :8900

class of student :x-c

book issued by the student :brain rules

author of the book issued :john medina

id of book :1256

date when book is issued :2019-06-06

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record
4.show all records

5.exit

what you want to do(1-5):8

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :8

student name :heer

admission no. of student :8654

class of student :x-d

book issued by the student :life of pi

author of the book issued :yaan martel

id of book :2378

date when book is issued :2019-04-04

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record
4.show all records

5.exit

what you want to do(1-5):4

sno name admn class book_name author_name book_id


date_of_issue

4 ram 7888 xii-c


deep water cal newport 4567
2019-07-07

4 reena 8455 xi-d


5am club rubin sharma 4589
2019-05-05

1 shelly 8472 xii-a


you can win shiv khera 1234
2019-09-09

2 simran 8473 xii-a


dept frr u zac bessonette 1235
2019-08-08

3 sita 8474 xii-b


your money jd roth 1255 2019-09-05

8 heer 8654 x-d


life of pi yaan martel 2378
2019-04-04

5 janvi 8888 x-a


personal mba josh kaujman 5643
2019-09-07

6 rohan 8898 ix-c


make good art neil gaiman 2367
2019-09-07

7 seema 8900 x-c


brain rules john medina 1256
2019-06-06

1.insert record
2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :9

student name :rani

admission no. of student :8009

class of student :xii-a

book issued by the student :essentalism

author of the book issued :greg mckeown

id of book :2590

date when book is issued :2019-03-06

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :10

student name :sam

admission no. of student :7654


class of student :xii-b

book issued by the student :spark

author of the book issued :john j ratey

id of book :4444

date when book is issued :2018-09-09

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :11

student name :naira

admission no. of student :7777

class of student :xii-d

book issued by the student :your money

author of the book issued :jd roth

id of book :4567

date when book is issued :2019-10-07

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record
2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :12

student name :sidharth

admission no. of student :7898

class of student :xii-c

book issued by the student :make good art

author of the book issued :neil gaiman

id of book :4567

date when book is issued :2019-10-10

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):1

enter serial no. :13

student name :kiran

admission no. of student :7890


class of student :xii-c

book issued by the student :maths rd sharma

author of the book issued :rd sharma

id of book :2345

date when book is issued :2019-04-10

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):4

sno name admn class book_name author_name book_id


date_of_issue

10 sam 7654 xii-b


spark john j ratey 4444 2018-09-09

11 naira 7777 xii-d


your money jd roth 4567 2019-10-07

4 ram 7888 xii-c


deep water cal newport 4567
2019-07-07

13 kiran 7890 xii-c


maths rd sharma rd sharma 2345
2019-04-10

12 sidharth 7898 xii-c


make good art neil gaiman 4567
2019-10-10
9 rani 8009 xii-a
essentalism greg mckeown 2590
2019-03-06

4 reena 8455 xi-d


5am club rubin sharma 4589
2019-05-05

1 shelly 8472 xii-a


you can win shiv khera 1234
2019-09-09

2 simran 8473 xii-a


dept frr u zac bessonette 1235
2019-08-08

3 sita 8474 xii-b


your money jd roth 1255 2019-09-05

8 heer 8654 x-d


life of pi yaan martel 2378
2019-04-04

5 janvi 8888 x-a


personal mba josh kaujman 5643
2019-09-07

6 rohan 8898 ix-c


make good art neil gaiman 2367
2019-09-07

7 seema 8900 x-c


brain rules john medina 1256
2019-06-06

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):2


enter serial no. :5

the current values are :

name = janvi

admn = 8888

class = x-a

book_name = personal mba

author_name = josh kaujman

book_id = 5643

date_of_issue = 2019-09-07

enter new values :

enter serial no. :5

student name :janvi

admission no. of student :8888

class of student :xi-a

book issued by the student :science

author of the book issued :s. chand

id of book :2356

date when book is issued :2019-04-08

>>>

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records


5.exit

what you want to do(1-5):4

sno name admn class book_name author_name book_id


date_of_issue

10 sam 7654 xii-b


spark john j ratey 4444 2018-09-09

11 naira 7777 xii-d


your money jd roth 4567 2019-10-07

4 ram 7888 xii-c


deep water cal newport 4567
2019-07-07

13 kiran 7890 xii-c


maths rd sharma rd sharma 2345
2019-04-10

12 sidharth 7898 xii-c


make good art neil gaiman 4567
2019-10-10

9 rani 8009 xii-a


essentalism greg mckeown 2590
2019-03-06

4 reena 8455 xi-d


5am club rubin sharma 4589
2019-05-05

1 shelly 8472 xii-a


you can win shiv khera 1234
2019-09-09

2 simran 8473 xii-a


dept frr u zac bessonette 1235
2019-08-08

3 sita 8474 xii-b


your money jd roth 1255 2019-09-05
8 heer 8654 x-d
life of pi yaan martel 2378
2019-04-04

5 janvi 8888 xi-a


science s. chand 2356
2019-04-08

6 rohan 8898 ix-c


make good art neil gaiman 2367
2019-09-07

7 seema 8900 x-c


brain rules john medina 1256
2019-06-06

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):

RESTART: C:\Users\SANJEEV\AppData\Local\Programs\Python\Python37\cs
project.py

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):4

sno name admn class book_name author_name book_id


date_of_issue
10 sam 7654 xii-b
spark john j ratey 4444 2018-09-09

11 naira 7777 xii-d


your money jd roth 4567 2019-10-07

4 ram 7888 xii-c


deep water cal newport 4567
2019-07-07

13 kiran 7890 xii-c


maths rd sharma rd sharma 2345
2019-04-10

12 sidharth 7898 xii-c


make good art neil gaiman 4567
2019-10-10

9 rani 8009 xii-a


essentalism greg mckeown 2590
2019-03-06

4 reena 8455 xi-d


5am club rubin sharma 4589
2019-05-05

1 shelly 8472 xii-a


you can win shiv khera 1234
2019-09-09

2 simran 8473 xii-a


dept frr u zac bessonette 1235
2019-08-08

3 sita 8474 xii-b


your money jd roth 1255 2019-09-05

8 heer 8654 x-d


life of pi yaan martel 2378
2019-04-04

5 janvi 8888 xi-a


science s. chand 2356
2019-04-08
6 rohan 8898 ix-c
make good art neil gaiman 2367
2019-09-07

7 seema 8900 x-c


brain rules john medina 1256
2019-06-06

1.insert record

2.modify record

3.delete record

4.show all records

5.exitwhat you want to do(1-5):3

enter serial no. :13

the current values are :

name = kiran

admn = 7890

class = xii-c

book_name = maths rd sharma

author_name = rd sharma

book_id = 2345

date_of_issue = 2019-04-10

are you sure to delete Y/Ny

1.insert record

2.modify record

3.delete record

4.show all records

5.exit

what you want to do(1-5):5


table in sql formed 
 
 
mysql> use shelly

Database changed

mysql> select * from library;

+------+----------+------+-------+-----------------+----------------+---------+---------------+

| sno | name | admn | class | book_name | author_name | book_id |


date_of_issue |

+------+----------+------+-------+-----------------+----------------+---------+---------------+

| 10 | sam | 7654 | xii-b | spark | john j ratey | 4444 | 2018-09-09 |

| 11 | naira | 7777 | xii-d | your money | jd roth | 4567 | 2019-10-07 |

| 4 | ram | 7888 | xii-c | deep water | cal newport | 4567 | 2019-07-07 |

| 13 | kiran | 7890 | xii-c | maths rd sharma | rd sharma | 2345 | 2019-04-10


|

| 12 | sidharth | 7898 | xii-c | make good art | neil gaiman | 4567 | 2019-10-10
|

| 9 | rani | 8009 | xii-a | essentalism | greg mckeown | 2590 | 2019-03-06 |

| 4 | reena | 8455 | xi-d | 5am club | rubin sharma | 4589 | 2019-05-05 |

| 1 | shelly | 8472 | xii-a | you can win | shiv khera | 1234 | 2019-09-09 |

| 2 | simran | 8473 | xii-a | dept frr u | zac bessonette | 1235 | 2019-08-08 |

| 3 | sita | 8474 | xii-b | your money | jd roth | 1255 | 2019-09-05 |


| 8 | heer | 8654 | x-d | life of pi | yaan martel | 2378 | 2019-04-04 |

| 5 | janvi | 8888 | xi-a | science | s. chand | 2356 | 2019-04-08 |

| 6 | rohan | 8898 | ix-c | make good art | neil gaiman | 2367 | 2019-09-07 |

| 7 | seema | 8900 | x-c | brain rules | john medina | 1256 | 2019-06-06 |

+------+----------+------+-------+-----------------+----------------+---------+---------------+

14 rows in set (0.00 sec)

mysql> select * from library order by sno;

+------+----------+------+-------+-----------------+----------------+---------+---------------+

| sno | name | admn | class | book_name | author_name | book_id |


date_of_issue |

+------+----------+------+-------+-----------------+----------------+---------+---------------+

| 1 | shelly | 8472 | xii-a | you can win | shiv khera | 1234 | 2019-09-09 |

| 2 | simran | 8473 | xii-a | dept frr u | zac bessonette | 1235 | 2019-08-08 |

| 3 | sita | 8474 | xii-b | your money | jd roth | 1255 | 2019-09-05 |

| 4 | ram | 7888 | xii-c | deep water | cal newport | 4567 | 2019-07-07 |

| 4 | reena | 8455 | xi-d | 5am club | rubin sharma | 4589 | 2019-05-05 |

| 5 | janvi | 8888 | xi-a | science | s. chand | 2356 | 2019-04-08 |

| 6 | rohan | 8898 | ix-c | make good art | neil gaiman | 2367 | 2019-09-07 |

| 7 | seema | 8900 | x-c | brain rules | john medina | 1256 | 2019-06-06 |

| 8 | heer | 8654 | x-d | life of pi | yaan martel | 2378 | 2019-04-04 |

| 9 | rani | 8009 | xii-a | essentalism | greg mckeown | 2590 | 2019-03-06 |

| 10 | sam | 7654 | xii-b | spark | john j ratey | 4444 | 2018-09-09 |

| 11 | naira | 7777 | xii-d | your money | jd roth | 4567 | 2019-10-07 |

| 12 | sidharth | 7898 | xii-c | make good art | neil gaiman | 4567 | 2019-10-10
|
| 13 | kiran | 7890 | xii-c | maths rd sharma | rd sharma | 2345 | 2019-04-10
|

+------+----------+------+-------+-----------------+----------------+---------+---------------+

14 rows in set (0.05 sec)

mysql>