0% found this document useful (0 votes)
23 views53 pages

Nalin Practical PY FINAL

Uploaded by

nalinm0925
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)
23 views53 pages

Nalin Practical PY FINAL

Uploaded by

nalinm0925
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/ 53

CERTIFICATE

Name : Nalin Manickam


Roll no. :
Institution : JSS PUBLIC SCHOOL, OOTY

This is to certify that NALIN MANICKAM of Class


XII B has prepared the report on the Project en-
titled
“FLIGHT MANAGEMENT” in computer laboratory
during the academic year 2024 – 2025 .

The report is the result of his efforts & en-


deavors. The
Report is found worthy of acceptance as final
project report for the subject Computer Science
of Class XII. He has
prepared the report under my guidance.

_______________________
___________________________

INTERNAL’S SIGNATURE EXTERNAL’S


SIGNATURE

___________________________

PRINCIPAL’S
SIGNATURE

ACKNOWLEDGEMENT

I would like to express a deep sense of


thanks & gratitude to my project guide
Mrs. Hema Mam PGT ( Computer
Science ) for guiding me immensely
through the course of the project. She
always evinced keen interest in my work.
Her constructive advice & constant
motivation have been responsible for the
successful completion of this project. My
sincere thanks goes to Mrs. Anita
Ramesh, Our Principal Mam, for her co-
ordination in extending every possible
support for the completion of this
project.I also thanks to my parents and
my friends for their motivation &
support.I must thanks to my classmates
for their timely help & support for
compilation of this project.Last but not
the least, I would like to thank all those
who had helped directly or indirectly
towards the completion of this project.

INDEX
S.No Page Date Signature
TITLE No.

PYTHON
1. THE AREA OF VARIOUS SHAPES

2. LIBRARY FUNCTIONS

3. CREATING MODULES AND PACKAGES

4. SIMULATING A DICE RANDOMLY

5. WRITING AND READING DATA

REMOVE ALL THE LINES THAT CONTAIN A SPECIFIC


6.
CHARACTER

7. TO READ A TEXT FILE USING BUILT IN FUNCTIONS

8. FIND THE MOST COMMONLY OCCURING WORD IN A TEXT FILE

TO READ LINES FROM A FILE AND DISPLAY THE OCCURRENCE


9.
OF A SPECIFIC WORD

10. WRITING DATA TO A BINARY FILE

11. TO READ AND DISPLAY OPERATIONS ON A BINARY


12. UPDATING DATA TO A BINARY FILE

13. WRITING INTO CSV FILE

14. CREATING A CSV FILE

15. READ/WRITE/SEARCH OPERATIONS ON CSV FILE

16. ENCYPTION AND DECRPYTION


17. STACKS
S.N Page Date Signature
o TITLE No.

MySQL

1. CREATING TABLES AND INSERTING RECORD

2. TO ADD COLUMNS AND UPDATE TABLE

3. TO DELETE RECORD BASED ON CONDITION

4. EXTRACTING DATA

5. USING FUNCTIONS

6. USING OTHER FUNCTIONS

7. GROUPING DATA

8. SORTING DATA

9. INTERFACE PYTHON
PYTHON
PROGRAM-1 TO CALCULATE THE AREA OF VARIOUS SHAPES
USING FUNCTIONS
AIM: To easily calculate the area of different shapes and to reduce
the program size and calculations by using functions
def rectangle(x,y):
area=x"y
return area
def square(x):
area=x**2
return area
def circle(x):
area=3.14*x*x
return area
def triangle(x,y):
area=0.5*x*y
return area
y="yes"
while y=="yes":
print("MENU")
print("Which area do you want to find?")
print("1.Area of triangle")
print("2.Area of rectangle")
print("3.Area of square")
print("4.Area of circle")
x=int(input("enter your choice:"))
if x==1:
base=int(input("enter base of the triangle:"))
height=int(input("enter height of the triangle:"))
a=triangle(base,height)
print(a)
elif x==2:
l=int(input("enter length of the rectangle:"))
b=int(input("enter the breadth of the rectangle"))
a=rectangle(l,b)
print(a)
elif x==3:
s=int(input("enter the side of the square:"))
a=square(s)
print(a)
elif x==4:
r=int(input("enter the radius of the circle:"))
a=circle(r)
print(a)
y=input("do you want to continue? reply with yes/no")

PROGRAM-2 LIBRARY FUNCTIONS


AIM: To enable us to use various functions in the math and string
module

import math
import string
y="yes"
while y=="yes":
print("MENU")
print("1.F 1.Functions in math module")
print("2.Functions in string module")
a=int(input("enter choice 1 or 2:"))
if a==1:
print("Choose the functions:")
print("1.sqrt")
print("2.exp")
print("3.pow")
print("4.sin")
print("5.cos")
print("6.radians")
b=int(input("choose a function:"))
if b==1:
x=int(input("enter the value to be calculated:"))
y=math.sqrt(x)
print(y)
elif b==2:
x=int(input("enter the value to be calculated:"))
y=math.exp(x)
print(y)
elif b==3:
x=int(input("enter value to be calculated:"))
a=int(input("enter power:"))
y=math.pow(x,a)
print(y)
elif b==4:
x=int(input("enter the value to calculated:"))
y=math.sin(x)
print(y)
elif b==5:
x=int(input("enter the value to calculated:"))
y=math.cos(x)
print(y)
elif b==6:
x=int(input("enter the value to calculated:"))
y=math.radians(x)
print(y)
elif a==2:
print("choose the functions:")
print("1.lower")
print("2.upper")
print("3.title")
print("4.find")
print("5.replace")
b=int(input("choose a function:"))

if b==1:
x=input("Enter the string:")
print(x.lower())
elif b==2:
x=input("Enter the string:")
print(x.upper())
elif b==3:
x=input("Enter the string:")
print(x.title())
elif b==4:
x=input("Enter the string:")
print(x.find(y))
elif b==5:
x=input("Enter the string:")
y=input("Enter word to be replaced:")
z=input("enter the new word:")
print(x.replace(y,z))
y=input("do you want to continue? (yes or no)")
PROGRAM-3 CREATING MODULES AND PACKAGES
AIM: To easily calculate Length conversions by importing
modules
def miletokm(x):
return x*1.609344
def kmtomile(x):
return x/1.609344
def feettoinches(x):
return x*12
def inchestofeet(x):
return x/12
#Mass Conversion
def kgtotonne(x):
return x*0.001
def tonnetokg(x):
return x/0.001
def kgtopound(x):
return x*2.20462
def poundtokg(x):
return x/2.20462

PROGRAM-4 SIMULATING A DICE RANDOMLY


AIM: To randomly pick numbers using the random
module
import random
y="yes"
while y=="yes":
print("The number rolled is", random.randint(1,6))
y=input("Do you want to roll the dice again? Type yes to continue:")

PROGRAM-5 WRITING AND READING DATA FROM A FILE


LINE BY LINE
AIM: To write the required data into the file and to read that
written data line by line.

f1=open("story.txt","w")
a=int(input("enter the limit:"))
for i in range(a):
name=input("enter name:")
f1.write(name)
f1.write("\n")
f1.close()
f1=open("story.txt","r")
for i in f1.readlines():
print(i)
f1.close()

PROGRAM-6 REMOVE ALL THE LINES THAT CONTAIN A


SPECIFIC CHARACTER IN A FILE AND WRITE IT INTO
ANOTHER FILE
AIM: To write all the lines which do not contain a specific
character into a new file

f1=open("p.txt","r")
f2=open("book.txt","w")
X=""
c=0
for x in f1.read():
if "w" not in x:
f2.write(x)
f1.close()
f2.close()
f2=open("book.txt","r")
for i in f2.readlines():
print(i)
f2.close()

PROGRAM-7 TO READ A TEXT FILE USING BUILT IN


FUNCTIONS
AIM: To display all the uppercase, lowercase, vowels,
consonants and
special characters in the text file.
f1=open("poem.txt","r")
uc=lc=sc=sp=vo=co=0
for i in f1.read():
if i.isalpha():
if i.isupper():
uc+=1
if i in ['a', 'e', 'i', 'o','u']:
vo+=1
else:
CO+=1
elif i.islower():
Ic+=1
if i in ['a','e','i', 'o','u']:
Vo+=1
else:
CO+=1
else:
sp+=1
print("number of uppercase characters:",uc)
print("number of lowercase characters:",lc)
print("number of special characters:",sp)
print("number of vowels:",vo)
print("number of consonants:",co)
f1.close()

PROGRAM-8 FIND THE MOST COMMONLY


OCCURING WORD IN A TEXT FILE
AIM: To find the most commonly occurring word in a
text file and listing the frequencies of words in a text file
f=open("poem.txt","r")
contents=f.read()
wordlist-contents.split()
wordfeq=[]
high=0
word=""
existing=[]
for i in wordlist:
count=wordlist.count(i)
if i not in existing:
wordfeq.append([i,count])
existing.append(i)
if count>high:
high=count
word=i
print("the word",word,"occurs maximum times", high,"times")
print("\nother words have frequencies:")
print(wordfeq)

PROGRAM-9 TO READ LINES FROM A TEXT FILE


AND DISPLAY THE OCCURRENCE OF A SPECIFIC
WORD
AIM: To read the file and to count the occurrence of a
word that has been given as the input.
file=open("poem.txt","r")
count=0
x=input("enter the word:")
for i in file:
words=i.split()
for w in words:
if w==x:
count+=1
print("the output is:",count)
file.close()

OUTPUT:
enter the word: We
the output is: 6

PROGRAM-10 WRITING DATA TO A BINARY FILE


AIM: To get student data(roll no, name, marks) from
user and write into a binary file.
import pickle
s={}
f=open("bin.dat", "wb")
choice="y"
while choice=="y":
rno=int(input("Enter your rollnumber:"))
marks-float(input("Enter mark:"))
name=input("Enter name:")
s['rno']=rno
s['marks"]=marks
s['name']=name
pickle.dump(s,f)
choice=input("Enter y to continue:")
f.close()

PROGRAM-11 TO READ AND DISPLAY OPERATIONS


ON A BINARY
FILE
AIM: To read and display students details from a binary
file and search for a record in a file.

import pickle
def read():
st={}
fin=open("bin.dat","rb")
try:
print("File bin.dat stores these records")
while True:
st=pickle.load(fin)
print(st)
except EOFError:
fin.close()
def display():
fin=open("bin.dat","rb")
found-False
a=int(input("Enter the record to be searched:"))
try:
print("Searching in file bin.dat")
while True:
st-pickle.load(fin)
if st['rno']==a:
print(st)
found=True
except EOFError:
if found==False:
print("No such records found in the file")
else:
print("search successfull")
fin.close()

ans="y"
while ans=="y":
print("MENU")
print("1.read and display the records")
print("2.search for records")
z=int(input("enter the function:"))
if z==1:
read()
if z==2:
display()
ans=input("Do you want to continue(y/n)")

PROGRAM-12 UPDATING DATA TO A BINARY FILE


AIM: To update the details of a student on a binary file
using pickle.
import pickle
st={}
found=False
fin=open("bin.dat","rb+")
a=int(input("Enter roll no to be updated:"))
b=input("Enter the detail to be updated:")
try:
while True:
rpos=fin.tell() st=pickle.load(fin)
if st["rno"]==a:
if b=="name":
c=input("Enter the new name:")
st[b]=c
elif b=="rno":
c=int(input("Enter the new rollno:"))
st[b]=c
elif b=="marks":
pending
c=float(input("Enter the new marks:"))
st[b]=c fin.seek(rpos)
pickle.dump(st,fin)
found=True
except EOFError:
if found==False:
print("sorry,no match found")
else:
print("record successfully updated")
fin.close()
fin=open("bin.dat","rb")
try:
while True:
st=pickle.load(fin)
print(st)
except EOFError:
fin.close()

PROGRAM -13 WRITING INTO CSV FILE


AIM: To create a csv file to store employee data (employee no, name,
designation, salary)
import csv
f=open("emp.csv","w")
empwriter=csv.writer(f)
empwriter.writerow(['empno', 'name', 'designation', 'salary'])
for i in range(3):
print("Employee record",i+1)
empno=int(input("Enter empno:"))
name=input("Enter name:")
designation=input("Enter the designation:")
salary=int(input("Enter salary:"))
emprec=[empno,name,designation,salary]
empwriter.writerow(emprec)
f.close()

PROGRAM-14 CREATING A CSV FILE


AIM: To get item details (code, description, price) for multiple items from the user
and create a csv file.
from csv import writer
def f_csvwrite():
f=open("goods.csv","w")
dt=writer(f)
dt.writerow(['code', 'description','price'])
|=[]
choice="y"
while choice=="y":
r=input("Enter code:")
b=input("Enter description:")
s=input("Enter price:")
l=[r,b,s]
dt.writerow(1)
choice=input("Enter y to continue:")
f.close()
f_csvwrite()

PROGRAM-15 READ/WRITE/SEARCH OPERATIONS ON CSV FILE


AIM: To create a menu driven program to write, read and search records on a civ file.
from csv import reader
def f_csvread(b):
f=open(b,"r")
dt=reader(f)
data=list(dt)
f.close()
print(data)
from csv import writer
def f_cswrite(c):
f=open(c,"w",newline="")
dt=writer(f)
01-1
n=int(input("enter the number of fields:"))
for i in range(n):
x=input("field name")
l.append(x)
dt.writerow()
n=int(input("enter no. of records"))
for i in range(n):
print(input("enter data1"))
q=input("enter data2")
dt.writerow([p.ql)
f.close()
from csv import reader
def srch(m):
f=open(m,"r")
s=reader(f)
n=input("data to be searched")
print(s)
flag=0
for row in s:
for field in row:
if field==n:
print("record found")
print(row)
print("*********
flag-1
break
if flag==0:
print("record not found")
f.close()
while True:
print("CSV file functions")
print("1.to read a file")
print("2.to write a file")
print("3.to search for a record")
print("4.exit")
ch=int(input("enter your choice"])
if ch==1:
b=input("enter the csv file with the extension .csv")
f_csvread(b)
if ch==2:
c=input("enter the csv file to create with the extension.csv")
f_csvwrite(c)
if ch==3:
m=input("enter the csv file in which you want the row to be searched with the
extension.csv")
srch(m)
if ch==4:
break

PROGRAM-16 ENCYPTION AND DECRPYTION


AIM: To encrypt and decrypt code.
def encrypt(strn,enkey):
return enkey.join(strn)
def decrypt(strn,enkey):
return strn.split(enkey)
mainstring=input("enter mainstring:")
encryptstr=input("enter encryption key:")
enstr-encrypt(mainstring, encryptstr)
dest=decrypt(mainstring, encryptstr)
destr="".join(dest)
print("The encrypted string is:",enstr)
print("The decrypted string is:", destr)

PROGRAM-17 STACKS
AIM: To create a stack
def isempty(stk):
if stk==[]:
return True
else:
return False

def push(stk,item):
stk.append(item)
top=len(stk)-1
def pop stk)
if isempty(stk):
return stack is empty"
else:
element=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)-1
return element
def peek(stk):
if isempty(stk):
return'stack is empty'
else:
top-len(stk)-1
return stk[top]
def display(stk):
ifisempty(stk):
print('stack is empty")
else:
top-len(stk)-1
print(stk[top])
for i in range(top-1,-1,-1):
print(stk[i])
stack=[]
top=None
while True:
print('stack operation")
print('1 push')
print("2.pop')
print('3.peek')
print('4.display")
print('5.exit')
ch=int(input('enter your choice(1 to 5):"))
if ch==1:
item=int(input('enter the element'))
push(stack,item)
elif ch==2:
element-pop(stack)
print('popped element is,element)
elif ch==3:
t=peek(stack)
print('top most elementis,t)
elif ch==4:
display(stack)
break
else:
print('invalid choice')
MySQL
MySQL

Part-1 : Data management


Practical - 1 : Creating table and inserting record

1. Create table department based on the following instance and


populate the table.

Column Data type Constraints


Dept Int Primary key
D_name Varchar(20) Not null
HOD Int Default-5
OUTPUT
2. Create table department based on the following instance and
populate the table.

Column Data type Constraints


S_no Integer Primary key
S_name Varchar(30) Not null
Salary Float N/A
Zone Varchar(15) N/A
Age Int Greater than 20
Grade Char(1) N/A
Dept Int Foreign key
(Dept table)
OUTPUT
Practical - 2 : To add columns and update table

1. Add a column manager_name in table


department varchar(30) and update table with
appropriate data

OUTPUT
Practical - 3 : To delete records based on criteria

1. Delete all records from staff table belonging


to south zone and having grade A

Source code :

OUTPUT :

2. To delete column Manager_name from table


department

Source code :

OUTPUT :
Practical 4 :Extracting data

1. Display S_no, S_name, Salary and


corresponding d_name of all employees whose
age is between 25 and 35 ( Both values inclusive
)

2. Display d_name and correspoonding S_name


from tables department and staff

3. Display S_name, Salary, Zone and income tax


of all the staff with appropriate column
headings ( Income tax to be calculated as 30%
of salary )
4. Display all details of staff of south zone
whose salary is greater than 50000

5. Display S_name, age , grade of staff whose


name starts with the character “D”
Practical 5 : Using Functions
1. Display maximum salary and minimum salary
from table employee under appropriate column
headings

2. Display the average and total salary from


staff
3. Count the number of records in the table staff

4. Count the number of distinct zones from table


staff
Practical-6:

1. Display d_name of table department in


uppercase

2. Remove leading and trailing spaces from


d_name field of department table
3. Concatenate d_name and dept of table
department having d_name as “Computer”

4. Display first three characters extracted


from d_name column of table department whose
is not 30
5. Display data/time-queries to return current
data, data only month only, year only, current
data and time and time at which the function
execute
Practical-7 : Grouping data

1. Display grade-wise total salary.

2. Display the maximum and minimum salary


in each zone

3. Display department-wise aveerage salary


having an average salary less than 700000
4. Display department-wise average salary
having dept count less than or equal to 2
Practical-8: Sorting Data

1. Display names from table employee in


ascending order.

2. Display all the details of employees in


ascending order of age from table employee.
3. Display all the details of employee in
descending order of grade and then by
ascending order of age from table employee

4. Display name and age of employee in


ascending order or names where age is between
20 and 40
Practical 9 : Display the details department
number , name, emp
no. ,emp_name,salary.Order the rows by emp no
with dept no. . These details should be only for
employee earning atleast Rs.60000

Practical 10 : JOINS

Equi-join : The join in which the columns are


compared for equality

All the columns would appear in the table being


joined are included even if identical.
Non-equi joins : a non-equi join is a query that
specifies some relationship other than equality
between the columns

Display employees details as name , Salary,


Zone, Grade only for east zone by comparing
Isal and Hsal
CARTESIAN PRODUCT :
Natural join is to avoid identical columns being
replicated (no on clause required )

Natur al join employee and department where


grade=”A”

Write query to print all the fields where salary is


greater than 60000 and grade=B

INTERFACE PYTHON
1. Using the concept of interface python create
a menu driven program to create table, insert
records and fetch records in sql

SOURCE CODE:
import mysql.connector as sql
con=sql.connect(host="localhost",user="root",p
asswd="rootadmin",\database="prac25")

if con.is_connected():
print("success!!!")
cur=con.cursor()

def createtable():
table="CREATE TABLE STUDENT1
(REGISTER_NO INTEGER,NAME VARCHAR(40),
CLASS\
VARCHAR(30), MARKS INTEGER, STREAM
VARCHAR(30))"
cur.execute(table)
con.commit()
print("table is created")
#createtable()
def insert();
a=int(input("enter the no of records to be
entered:"))
for i in range(a):
reg=int(input("enter the register no of the
students:"))
name=input("enter the name of the
student:")
class1=input("enter the class of the
students:")
marks=float(input("enter the marks of the
students"))
stream=input("enter the stream of the
students:")
insert1="INSERT INTO STUDENT1 VALUES
(0.'0','0','0')".format(reg, name,class1, marks,
stream)
cur.execute(insert(1)
con.commit()
def fetch():
cur.execute("SELECT*FROM STUDENT1")
d=cur.fetchall()
for row in d:
print(row)
def fetch1():
cur.execute("SELECT * FROM STUDENT1")
d=cur.fetchone()
print(d)
def fetch2():
cur.execute("SELECT * FROM STUDENT1")
a=int(input("enter the no of records to be
fetched:"))
d=cur.fetchmany(a)
for row in d:
print(row)
while True:
print("----MENU----")
print("1.creating table")
print("2.inserting records")
print("3.fetching all the records")
print("4.fetching one record")
print("5.fetching many records")
print("6.exit")
ch=int(input("enter your choice:"))
if ch==1:
createtable()
elif ch==2:
insert()
elif ch==3:
fetch()
elif ch==4:
fetch1()
elif ch==5:
fetch2()
elif ch==6:
break
$$$$$$$$$$$

6.exit
enter your choice:4
(1, 'lakshmi', '12', 98, 'group v')
----MENU----
1.creating table
2.inserting records
3.fetching all the records
4.fetching one record
5.fetching many records ster
6.exit
enter your choice:5
enter the no of records to be fetched:3
(1, 'lakshmi', '12', 98, 'group v')
(101, 'lakshmi', '12', 98, 'group v')
(102, 'praniksha', '12', 97, 'group v')
----MENU----
1.creating table
2.inserting records
3.fetching all the records
4.fetching one record
5.fetching many records
6.exit
enter your choice:6

check blue file


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

############# MYSQL PIC


############
2.updating
def update():
a=int(input("enter the register no of records
to be updated:"))
print("CHOOSE THE FIELD TO BE UPDATED")
print("1.NAME")
print("2.CLASS")
print("3.STREAM")
print("4.MARK")
ch=int(input("enter your choise"))
if ch==1:
name=input ("enter new student name:")
cur.execute("update student1 set
name='{}' where (register_no={})"\
.format(name,a))
con.commit()
print("name updated")
elif ch==2:
clas=input("enter new class:")
cur.execute("update student1 set
class='{}' where (register_no={})}"\
.format(clas,a))
print("class updated")
elif ch==3:
group=input("enter new group:")
cur.execute("update student1 set
stream='{}' where (register_no={})"\
.format(group,a))
con.commit()
print("group updated")
elif ch==4:
mark=float(input("enter new mark:"))
cur.execute("update student1 set
marks={} where (register_no={})"\
.format(mark,a))
con.commit()
print("mark updated")
update()
OUTPUT
success!!!
enter the register no of records to be updated:
101
CHOOSE THE FIELD TO BE UPDATED
1.NAME
2.CLASS 3.STREAM
4.MARK
enter your choise1
enter new student name:lakshmishree
name updated
enter
enter the register no of records to be
updated:102
CHOOSE THE FIELD TO BE UPDATED
1.NAME
2.CLASS
3.STREAM
4.MARK
enter your choise2
enter new class:11
class updated
enter the register no of records to be updated:
103
CHOOSE THE FIELD TO BE UPDATED
1.NAME
2.CLASS
3.STREAM
4.MARK
enter your choise3
enter new group: group i
group updated
enter the register no of records to be
updated:101
CHOOSE THE FIELD TO BE UPDATED
1.NAME
2.CLASS
3.STREAM
4.MARK
enter your choise4
enter new mark:99
mark updated

INTERFACE PY -2 REVISED

INTERFACE PYTHON
1. Using the concept of interface python create
a menu driven program to create table, insert
records and fetch records in sql

SOURCE CODE:
import mysql.connector as sql
con=sql.connect(host="localhost", user="root",
passwd="rootadmin",\
database="prac25")
if con.is_connected():
print("success!!!")
cur=con.cursor()

def createtable():
table="CREATE TABLE STUDENT1
(REGISTER_NO INTEGER,NAME VARCHAR(40),
CLASS\
VARCHAR(30), MARKS INTEGER, STREAM
VARCHAR(30))"
cur.execute(table)
con.commit()
print("table is created")
#createtable()
def insert();
a=int(input("enter the no of records to be
entered:"))
for i in range(a):
reg=int(input("enter the register no of the
students:"))
name=input("enter the name of the
student:")
class1=input("enter the class of the
students:")
marks=float(input("enter the marks of the
students"))
stream=input("enter the stream of the
students:")
insert1="INSERT INTO STUDENT1 VALUES
(0.'0','0','0')".format(reg, name,class1, marks,
stream)
cur.execute(insert(1)
con.commit()
def fetch():
cur.execute("SELECT*FROM STUDENT1")
d=cur.fetchall()
for row in d:
print(row)
def fetch1():
cur.execute("SELECT * FROM STUDENT1")
d=cur.fetchone()
print(d)
def fetch2():
cur.execute("SELECT * FROM STUDENT1")
a=int(input("enter the no of records to be
fetched:"))
d=cur.fetchmany(a)
for row in d:
print(row)
while True:
print("----MENU----")
print("1.creating table")
print("2.inserting records")
print("3.fetching all the records")
print("4.fetching one record")
print("5.fetching many records")
print("6.exit")
ch=int(input("enter your choice:"))
if ch==1:
createtable()
elif ch==2:
insert()
elif ch==3:
fetch()
elif ch==4:
fetch1()
elif ch==5:
fetch2()
elif ch==6:
break
$$$$$$$$$$$

6.exit
enter your choice:4
(1, 'lakshmi', '12', 98, 'group v')
----MENU----
1.creating table
2.inserting records
3.fetching all the records
4.fetching one record
5.fetching many records ster
6.exit
enter your choice:5
enter the no of records to be fetched:3
(1, 'lakshmi', '12', 98, 'group v')
(101, 'lakshmi', '12', 98, 'group v')
(102, 'praniksha', '12', 97, 'group v')
----MENU----
1.creating table
2.inserting records
3.fetching all the records
4.fetching one record
5.fetching many records
6.exit
enter your choice:6

check blue file


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

############# MYSQL PIC


############

2.updating
def update():
a=int(input("enter the register no of records
to be updated:"))
print("CHOOSE THE FIELD TO BE UPDATED")
print("1.NAME")
print("2.CLASS")
print("3.STREAM")
print("4.MARK")
ch=int(input("enter your choise"))
if ch==1:
name=input ("enter new student name:")
cur.execute("update student1 set
name='{}' where (register_no={})"\
.format(name,a))
con.commit()
print("name updated")
elif ch==2:
clas=input("enter new class:")
cur.execute("update student1 set
class='{}' where (register_no={})}"\
.format(clas,a))
print("class updated")
elif ch==3:
group=input("enter new group:")
cur.execute("update student1 set
stream='{}' where (register_no={})"\
.format(group,a))
con.commit()
print("group updated")
elif ch==4:
mark=float(input("enter new mark:"))
cur.execute("update student1 set
marks={} where (register_no={})"\
.format(mark,a))
con.commit()
print("mark updated")
update()
OUTPUT
success!!!
enter the register no of records to be updated:
101
CHOOSE THE FIELD TO BE UPDATED
1.NAME
2.CLASS 3.STREAM
4.MARK
enter your choise1
enter new student name:lakshmishree
name updated
enter
enter the register no of records to be
updated:102
CHOOSE THE FIELD TO BE UPDATED
1.NAME
2.CLASS
3.STREAM
4.MARK
enter your choise2
enter new class:11
class updated
enter the register no of records to be updated:
103
CHOOSE THE FIELD TO BE UPDATED
1.NAME
2.CLASS
3.STREAM
4.MARK
enter your choise3
enter new group: group i
group updated
enter the register no of records to be
updated:101
CHOOSE THE FIELD TO BE UPDATED
1.NAME
2.CLASS
3.STREAM
4.MARK
enter your choise4
enter new mark:99
mark updated

You might also like