Final Practical Examination 2022 - 23
Final Practical Examination 2022 - 23
Note : You are given set of programs and connectivity for the preparation of practical file.
1. You have to cut each of the program from the given material and paste it in Python editor
and try it . You have to change few variables and all constant values as per your wish
in each program . [ Variables and constants must be different for every student ]
2. Nearly each is carrying an output . It is for your convenience . Do not copy down the
output in your Practical File.
3. After successful execution of each program you have to make a word file of complete
material . ( Keep saving it in WORD File )
5. Second page : It must contain CONTENTS in a proper sequence as given on next page
in your own handwriting .
6. Third Page Onward : You have to use Bio Rules paper for writing Programs . Every
program must start from NEW PAGE with heading as “PRACTICAL NO. : ...” and a
question underneath . Write related program in proper manner
Likewise , you have to write 15 Programs
Remember : You have to change few variables and all constant values as per your wish
in each program .
7. Use BIO FILE COVER : Cover it brown paper and write everything on it as
Cover page given on next page .
USE BIO RULED PAGES FOR WRITING PROGRAMS
Important : Every student will prepare his own Practical File
9. Make use of proper lace to insert all pages and put them in file cover and keep it ready
for correction .
Note : After some days I will plan to give you a project in Python . You will have to prepare
a similar type of project .
First Page as Cover Page : ( Adjust it in your complete A4 plane page )
Class XII
TERM - 1
Session : 2022 - 23
Submitted By : Submitted To :
Contents
1. Program question will be here
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
Program No. - 1
Program No. - 2
#* * * * M A I N * * * *
n = int(input("Enter the no. of rows "))
pas_triangle( n ) # Call statement
Program No. - 4
index = lsearch(ar, no )
Aim : Write Menu Driven program in Python for Creation, Appending and Reading of
a Text data File in Python
def make_file( ):
file = open("try.txt","w")
sen = input("Enter a sentence please ")
file.write(sen)
file.close( )
print("File is created ")
def add_data( ):
file = open("try.txt","a")
sen = input("Add a sentence please ")
file.write(sen)
file.close( )
print("File is appended ")
def display( ):
import time
try :
file = open("try.txt","r")
x = file.read(1) # It reads character by character
while x :
if not x :
break
else :
print (x,end= "")
time.sleep(.2)
x = file.read(1)
file.close( )
except IOError :
print("File does not exists")
def finish( ):
print ("Thanks ! I quit")
#* * * * * * MAIN PROGRAM * * * *
dict = { 1 : make_file, 2 : add_data , 3 : display , 4 : finish }
choice = 0
while(choice != 4) :
print ("\n\nMain - Menu ")
print ("1. Creation of a Text data File ‘try.txt’")
print ("2. Appending of a Text data File ")
print ("3. Reading of a Text data File")
print ("4. Quit the program")
choice = int(input("Enter your choice please : "))
dict.get(choice )( )
PROGRAM NO. - 6
Aim : Write a program for Creation & Reading of Text data file . Logic should calculate
the Frequency of a particular word in the Text data file as the user’s wish
def make_file( ) :
file = open("goo.txt","w") Main - Menu
sen = input("Enter a sentence please ") 1. Creation of a Text data File
file.write(sen) 2. Normal Reading of DAta File
file.close( ) 3. To find the frequency of a word my
print("File is created ") 4. Quit the program
def display( ): Enter your choice please : 2
import time In my house I have my desk with my pen .
try :
file = open("goo.txt","r") Main - Menu
x = file.read(1) 1. Creation of a Text data File
while x : 2. Normal Reading of DAta File
if not x : 3. To find the frequency of a word my
print ("End of File") 4. Quit the program
else : Enter your choice please : 3
print (x,end= "") my occurs 3 times
time.sleep(.1)
x = file.read(1)
file.close( )
except IOError :
print("File Not Found ! ! ! ")
def finish( ) :
print ("Thanks ! I quit")
def count_word( ) :
try :
file = open("goo.txt","r")
c = file.read( ) # Complete file is read in c
word = c.split( ) # File is stored word wise
wd = input("Enter a word to be searched and counted : ")
count = 0
for i in word :
if i == wd :
count = count + 1
print("my occurs ",count," times")
file.close( )
except IOError :
print("File Not Found ! ! ! ")
# * * * * * * * MAIN * * * * * * * * * *
dict = { 1 : make_file, 2 : display, 3 : count_word, 4 : finish }
choice = 0
while(choice != 4):
print ("\n\n Main - Menu ")
print ("1. Creation of a Text data File ")
print ("2. Normal Reading of DAta File")
print ("3. To find the frequency of a word my")
print ("4. Quit the program")
choice = int(input("Enter your choice please : "))
dict.get(choice )( )
PROGRAM NO. - 7
Aim : Write a progrm for Creation and Reading of Text data file . Logic should Convert
1st letter of each word in capital
def make_file( ) :
file = open("goo.txt","w")
sen = input("Enter a sentence ")
file.write(sen)
file.close( ) Main - Menu
print("File is created ") 1. Creation of a Text data File
def display( ) : 2. Normal Reading of DAta File
import time 3. To convert First letter of each word as
file = open("goo.txt","r") Capital
x = file.read(1) 4. Quit the program
while x : Enter your choice please : 1
if not x : Enter a sentence :
print ("End of File") we Are going to Play Football now.
else : File is created
print (x,end= "") Main - Menu
time.sleep(.1) 1. Creation of a Text data File
x = file.read(1) 2. Normal Reading of DAta File
file.close( ) 3. To convert First letter of each word as Capital
def finish( ) : 4. Quit the program
print ("Thanks ! I quit") Enter your choice please : 3
def logic( ) : We Are Going To Play Football Now.
import time
try :
file = open("goo.txt","r")
c = file.read( ) # Reads full Data FIle
word = c.split( ) # Converts string into words in the form of a list
for i in word :
if i[0].islower( ) :
x =i.capitalize( ) # Converts 1st character of a word into capital
print (x,end= " ")
time.sleep(.5)
else :
print (i,end= " ")
time.sleep(.5)
file.close( )
except IOError :
print("File Not Found ! ! ! ")
# * * * * * * MAIN * * * * * * *
dict = { 1 : make_file, 2 : display, 3 : logic, 4 : finish }
choice = 0
while(choice != 4):
print ("\n\n Main - Menu ")
print ("1. Creation of a Text data File ")
print ("2. Normal Reading of Data File")
print ("3. To convert First letter of each word as Capital")
print ("4. Quit the program")
choice = int(input("Enter your choice please : "))
dict.get(choice )( )
PROGRAM NO. - 8
Aim : Write a Program to transfer all sentences starting with lowercase from one data file
“goo.txt” to another data file “transfer.txt” .
def make_file( ) : Main - Menu
file = open("goo.txt","w") 1. Creation of a Text data File
ch = 'y' 2. Normal Reading of a file
while ch == 'y' : 3. Lowercase sentence printing
sen = input("Enter a sentence please ") 4. Quit the program
file.write(sen+"\r") Enter your choice please : 2
ch = input("Any more sentence please (Y/N : ") 1. for "goo.txt" and
file.close( ) 2. for "treansfer.txt"
print("File is created ") Enter name of a
def display( ) : data file please : goo.txt
print("""1. for "goo.txt" and 2. for "transfer.txt" """) I am going
name = input("Enter name of a data file please : ") he is not comin
import time well OK!
try : My book
file = open(name,"r")
x = file.readlines( )
for line in x :
print(line,end = "")
time.sleep(.5)
file.close( )
except IOError :
print("File Not Found ! ! ! ")
def transfer_lowercase( ):
import time
g = open("transfer.txt","w") Main - Menu
with open('goo.txt',"r") as f: 1. Creation of a Text data File
x = f.readlines( ) 2. Normal Reading of a file
for line in x : 3. Lowercase sentence printing
if line[0].islower( ): 4. Quit the program
g.write(line+"\r") Enter your choice please : 3
f.close( ) Data Transferred
g.close( ) Main - Menu
print("Data Transferred") 1. Creation of a Text data File
def finish( ) : 2. Normal Reading of a file
print ("Thanks ! I quit") 3. Lowercase sentence printing
#******* MAIN ****** 4. Quit the program
dict = { 1 : make_file, 2 : display, Enter your choice please : 2
3 : transfer_lowercase, 4 : finish 1. for "goo.txt" and 2. for "treansfer.txt"
} Enter name of a data file please : transfer.txt
choice = 0 he is not comin
while(choice != 4): well OK!
print ("\n\n Main - Menu ")
print ("1. Creation of a Text data File ")
print ("2. Normal Reading of a file ")
print ("3. Lowercase sentence printing ")
print ("4. Quit the program")
choice = int(input("Enter your choice please : "))
dict.get(choice )( )
PROGRAM NO. - 9
Aim : Write Creation and Reading for Text data file . Program logic should print records
for balance greater than 1000
def heading( ) :
print("-"*40)
print("A/C No.","\t","Name","\t\t","balance")
print("-"*40)
def creation( ) :
file = open("bank.txt","w")
ch = 'y'
while ch == 'y' :
ac = int(input("Enter your A/C NO. please : "))
na = input("Enter your name please : ")
bal = int(input("Enter your Balance please : "))
file.write(str(ac)+"\t"+na+"\t"+str(bal)+"\r")
file.flush( )
ch = input("Any more sentence please (Y/N : ")
file.close( )
print("File is created ")
def finish( ) :
print ("Thanks ! I quit")
def display( ):
import time
file = open("bank.txt","r")
x = file.readlines( )
heading( )
for line in x :
word = line.split( ) # in a list form for each record
if int(word[2]) > 1000 :
for i in range (len(word)) :
print(word[i],end="\t\t") Main - Menu
time.sleep(.1) 1. Creation of a Text data File
print("\n") 2.Reading records are per conditioon
print("-"*40) 3. Quit the program
file.close( ) Enter your choice please : 2
----------------------------------------
#******* MAIN ******** A/C No. Name balance
dict = { 1 : creation, ----------------------------------------
2 : display, 102 Jassal 2000
3 : finish
}
choice = 0 103 Joshi 3000
while(choice != 3):
print ("\n\n Main - Menu ")
print ("1. Creation of a Text data File ") ----------------------------------------
print ("2. Normal Reading of a file ")
print ("3. Quit the program")
choice = int(input("Enter your choice please : "))
dict.get(choice )( )
Program No. - 10
Aim : Write Simple creation , appending and reading of Binary Data File. :
(Page 1 of 2 )
def heading( ) :
print("-"*40)
print("A/C No.","\t","Name","\t\t","balance")
print("-"*40)
def creation( ) :
import pickle
f = open("bank.dat", "wb") # wb for writing binary data file
ch = 'y'
while ch == 'y' :
list = [ ]
ac = int(input("Enter your A/C NO. please : "))
list.append(ac)
na = input("Enter your name please : ")
list.append(na)
bal = int(input("Enter your Balance please : "))
list.append(bal)
pickle.dump(list, f) # RAM to SM
ch = input("Any more Record please (Y/N ) : ")
f.close( )
print("File is created ")
def appending( ) :
import pickle
f = open("bank.dat", "ab") # wb for writing binary data file
ch = 'y'
while ch == 'y' :
list = [ ]
ac = int(input("Enter your A/C NO. please : "))
list.append(ac)
na = input("Enter your name please : ")
list.append(na)
bal = int(input("Enter your Balance please : "))
list.append(bal)
pickle.dump(list, f) # RAM to SM
ch = input("Any more sentence please (Y/N ) : ")
f.close( )
print("File is Appended ")
def display( ): (Page 2 of 2 )
import pickle
import time
heading( )
try :
with open("bank.dat","rb") as f : # rb for reading binary data file
try :
x = pickle.load( f ) # SM to RAM
while True :
for i in x :
print(i,end="\t\t")
time.sleep(.5)
x = pickle.load( f ) # SM to RAM
print()
print("-"*40)
except EOFError :
print("EoF . . . .")
f.close( )
except IOError :
print("File Not Found ")
def finish( ) :
print ("Thanks ! I quit")
#*****MAIN******
dict = { 1 : creation, 2 : appending, 3 : display, 4 : finish }
choice = 0
while(choice != 4):
print ("\n\n Main - Menu ")
print ("1. Creation of a binary data File ")
print ("2. Appending of a binary data File ")
print ("3. Reading of a binary data file ")
print ("4. Quit the program")
choice = int(input("Enter your choice please : "))
Program No. 11
Aim : Write a Menu Driven program for creating a dictionary under Binary data file and
Read it in a proper manner
def creation( ) :
import pickle
file = open("a.dat", "wb")
ans = 'y'
while ans == 'y' :
emp = {}
emp['code'] = int(input("Enter employee code: "))
emp['name'] = input("Enter employee Name: ")
emp['salary'] = int(input("Enter salary: "))
pickle.dump(emp, file)
ans = input("Any more records plaese (y/n) : ")
file.close()
print("File is created ")
def display( ):
import pickle
import time
heading( )
#f = open("a.dat","rb") # rb for reading binary data file
try :
with open("a.dat","rb") as f : # rb for reading binary data file
try :
while True :
emp = pickle.load(f)
if emp['salary'] > 300:
print(emp)
# OR
print(emp['code'],"\t",emp['name'],"\t\t",emp['salary'])
print("-"*40)
except EOFError :
print("EoF . . . .") dict = { 1 : creation, 2 : display, 3 : finish }
f.close( ) choice = 0
except IOError : while(choice != 3):
print("File Not Found ") print ("\n\n Main - Menu ")
print ("1. Creation of a binary data File ")
def finish( ) : print ("2. Reading of a binary data file on condition")
print ("Thanks ! I quit") print ("3. Quit the program")
choice = int(input("Enter your choice please : "))
dict.get(choice )( )
Program No. 12
( Page 1 of 3 )
Aim : Write a program to delete a record from Binary data file with Creation ,
Appending , Reading and Removing a record
import pickle
import os
def create( ):
f = open("result.dat","wb")
ans = "y"
while ans == "y" :
rec = [ ]
print("\tCreating records for result data file ")
rn = int(input("\tEnter Roll No. : "))
name = input("\tEnter Name : ")
phy = int(input("\tEnter Marks in Physics : "))
chem = int(input("\tEnter Marks in Chemistry : "))
math = int(input("\tEnter Marks in Maths : "))
tot = phy + chem + math
av1 = tot / 3
av = int(av1)
if av > 70 :
res = " First Division "
elif av > 60 and av <= 70 :
res = " Second Division "
elif av > 50 and av <= 60 :
res = " Third Division "
else :
res = "FAIL"
rec.append([rn,name,phy,chem,math,tot,av,res])
pickle.dump(rec,f)
ans = input("Any more record please ( y/n) : ")
f.close( )
print("\t Data File Result is Created . . .")
def add_a_record():
f = open("result.dat","ab")
ans = "y"
while ans == "y" :
rec = [ ]
print("\tCreating records for result data file ")
rn = int(input("\tEnter Roll No. : "))
name = input("\tEnter Name : ")
phy = int(input("\tEnter Marks in Physics : "))
chem = int(input("\tEnter Marks in Chemistry : "))
math = int(input("\tEnter Marks in Maths : "))
tot = phy + chem + math
av1 = tot / 3
av = int(av1)
if av > 70 :
res = " First Division "
elif av > 60 and av <= 70 :
res = " Second Division "
elif av > 50 and av <= 60 : ( Page 2 of 3 )
res = " Third Division "
else :
res = "FAIL"
rec.append([rn,name,phy,chem,math,tot,av,res])
pickle.dump(rec,f)
ans = input("Any more record please ( y/n) : ")
f.close( )
print("\t Data File Result is Created . . .")
def display( ):
print("\t Reading of result data File\n ")
print("\t RESULT FOR CLASS XII A & B")
print("\t **************************")
import time
try :
with open("result.dat","rb") as f : # rb for reading binary data file
print("-"*78)
mat = "%2s %10s %5s %5s %5s %10s %10s %10s"
print(mat % ("R.No.","Name","Phys.","Chem."," Maths","Total","Average","Result"))
print("-"*78)
try :
rec= pickle.load(f)
while True:
mat = "%2s %10s %5s %5s %5s %10s %10s %10s"
for re in rec :
rn = re[0]
name = re[1]
phy = re[2]
chem = re[3]
math = re[4]
tot = re[5]
av = re[6]
res = re[7]
print(mat % (rn,name,phy,chem,math,tot,av,res))
time.sleep(0.5)
rec= pickle.load(f)
except EOFError:
print("EOF . . . ")
print("."*78)
f.close()
except IOError:
print("Files is not preesnt ")
def remove_a_record( ): ( Page 3 of 3 )
print("\tDeleting a Record as per useer's wish")
print("\t*************************************")
import os
try :
f = open("result.dat","rb")
f1=open("temp.dat","wb")
rn = int(input("\tEnter the Roll No. for which a record is to be deleted : "))
try:
rec= pickle.load(f)
while True:
for record in rec:
if record[0]!= rn :
pickle.dump(rec,f1)
else :
continue
rec= pickle.load(f)
except EOFError :
print( "\tEOF . . . ")
f.close( )
f1.close( )
except IOError:
print("File is not found ")
os.remove("result.dat")
os.rename("temp.dat","result.dat")
print("\tRecord for R. No. ",rn," is deleted . . .")
def finish( ) :
print("\t * * * Thank you very much * * *")
#*****MAIN*******
choice = 0
dict = { 1 : create , 2 : add_a_record , 3 : display , 4 : remove_a_record , 5 : finish}
while (choice != 5 ):
print("\t\tMAIN MENU")
print("\t1. CREATION OF DATA FILE emp.dat")
print("\t2. APPENDING OF DATA FILE emp.dat")
print("\t3. READING OF DATA FILE emp.dat")
print("\t4. DELETING A RECORD in emp.dat")
print("\t5. EXIT THE PROGRAM")
choice = int(input("\tEnter your choice "))
dict.get(choice)( )
Program No. 13 ( CSV Files )
# CSV file Creation & Reading using write and read function
# We are creating result.csv without new line argument
# Means without using delimiter as newline = '\r\n' in open function
# We use only f = open("result.csv","w")
# It will provide empty row between the two records
# If we do not provide newline argument ,
# EOL ( end of line) translation takes place
# which results into blank row after each record while reading
import csv
def creation( ) :
# opening a csv file
f = open("result.csv","w")
# Creating a write object for a file
result = csv.writer(f) # Writer object declaration
result.writerow(['Roll No', 'Name', 'Marks']) # heading being stored
ans = 'y'
c=0
while ans == 'y' or ans == 'Y' :
c=c+1
print("Student Record No. ",c)
rn = int(input("Enter your Roll No. : "))
na = input("Enter your name : ")
marks = int(input("Enter your marks : "))
stru = [ rn,na,marks]
result.writerow(stru) # Written in SM
ans = input("Any more record please (y/n) : ")
f.close( )
def reading( ) :
# opening a csv file for reading
f = open("result.csv","r")
# Creating a read object for a file
result = csv.reader(f) # reader object declaration
for rec in result :
print(rec)
f.close( )
def finish( ):
print("Thank you for Trying . . .")
# * * * * *M A I N M E N U * * * *
dict = { 1 : creation , 2 : reading , 3 : finish }
choice = 0
while(choice != 3) :
print("MAIN - MENU ")
print("*********** ")
print("1. Creation of CSV File . . ")
print("2. Reading of CSV File . . ")
print("3. Closing of of CSV File . . ")
choice = int(input("Enter your choice please : "))
dict.get(choice)( )
Program No. 14 ( CSV File )
# CSV file Creation & Reading using write and read function
# We are creating result.csv with new line argument
# Means using delimiter as newline = '\r\n' in open function
# It can be done in two ways :
# 1. in open function : newline = '\r\n'
# 2. in open function : newline = ''
# It will remove the empty rows between the two records.
import csv
def creation( ) :
# opening a csv file
f = open("result.csv","w", newline = '')
# Creating a write object for a file
resultwriter = csv.writer(f) # Writer object declaration
resultwriter.writerow(['Roll No', 'Name', 'Marks']) # heading being storeed
ans = 'y'
c=0
while ans == 'y' or ans == 'Y' :
c=c+1
print("Student Record No. ",c)
rn = int(input("Enter your Roll No. : "))
na = input("Enter your name : ")
marks = int(input("Enter your mnarks : "))
stru = [ rn,na,marks]
resultwriter.writerow(stru) # Written in SM
ans = input("Any more record please (y/n) : ")
f.close( )
def findpos(ar,item) :
size = len(ar)
if item < ar[0]:
return 0
else :
pos = -1
for i in range(size -1 ):
if ar[i] < item and item < ar[i+1] :
pos = i + 1
break
if pos == -1 and i <= size - 1 :
pos = size
return pos
# - - - - - MAIN - - - - -
index = findpos(ar, no )
print (" Righ position is = ",index+1)
shiftvalues(ar, index )
ar[index] = no
#Display :
PROGRAM NO. - 17
def findpos(ar,item) :
size = len(ar)
if item < ar[0] and item > ar[size-1]:
return -1
else :
pos = -1
k=0
for i in range(size -1 ):
if ar[i] == item :
pos = i + 1
k=1
break
if k == 1 :
print ("The array is =",ar)
print ("The position of ",item," is = ",pos)
return pos
else :
return -1
# - - - - - MAIN - - - - -
n = int(input("Enter the size of the list "))
ar = [ ]
# Selection Sort
def selection( ) : # Exit the program
ar = [ 287,410,265,106,333 ] def exit( ) :
print ("Given List is ",ar) print("Thank you very much ")
n = len(ar)
for i in range (0, n-1 ) : # * * ** MAIN * ** * * *
for j in range ( i+1, n) : choice = 0
if ar[ i ] > ar[ j ]: dict = { 1 : selection , 2 : bubble , 3 : insertion , 4 :
ar[ i ] , ar[ j ] = ar[ j ] , ar[ i ] exit}
print ("The output will be ",ar)
while choice != 4 :
print("******* MAIN MENU ***** ")
# Bubble Sort print("1. To show the working of Selection Sort")
def bubble( ) : print("2. To show the working of Bubble Sort")
ar = [ 2,9,3,7,1 ] print("3. To show the working of Insertion Sort")
print ("Original List as an Array is ",ar) choice = int(input("Enter your choice please "))
# Working dict.get(choice)( )
n = len(ar)
m=1
while m == 1 :
for j in range(n-1) :
if ar[j] > ar[j+1]:
ar[j],ar[j+1] = ar[j+1],ar[j]
m=1
break
else :
m=0
print ("The sorted list is ",ar)
# Insertion Sort
def insertion( ) :
ar = [ 22,55,11,44,33 ]
sub = [ ]
print ("Given List is ",ar)
n = len(ar)
for i in range (0, n-1 ) :
for j in range ( i+1, 0 , -1) :
if ar[ j ] < ar[ j-1 ]:
ar[ j ] , ar[ j-1 ] = ar[ j-1 ] , ar[ j ]
print ("The output will be ",ar)
SQL Query No. 1
Go through the table “staff” given below and write queries for Q. No. 1 to Q. No. 5. :
Try all the queries on a MySQL and then proceed with the file preparation .
[ You have to write the question and answer in terms of query in your File ]
Q.1Display all the records from the table “staff” for all the persons from Katni .
mysql> select * from staff where city ='Katni';
Q.4 Display Grade and sum of salary for all the employees group by Grade .
mysql> select grade, sum(salary) from staff group by grade;
Q.5 Update the salary to 10000 for those employees whose salary is NULL .
mysql> update staff set salary = 10000 where salary is NULL;
mcon = msql.connect( host = 'localhost', user = 'root', passwd = 'student', database = 'anand')
# Password of MySQL what you gave must be entered
# Create a database and use it here in the above statement
if mcon.is_connected( ):
print("Successful connection to Mysql database")
dict = { 1 : insert_fixed_records,
2 : display_records,
3 : finish
}
while(choice != 3):
print ("\n\n Main - Menu ")
print ("1. Insert fixed records given here")
print ("2. Printing all the records")
print ("3. Quit the program")
choice = int(input("Enter your choice please : "))
dict.get(choice)( )
def insert_record_on_wish( ) :
list = [ ]
no_rec = int(input("How many records you want to enter ? "))
for i in range(0,no_rec) :
a=[]
RollNo = int(input("Enter your Roll No. : ")) ; a.append(RollNo)
Name = input("Enter your Name : ") ; a.append(Name)
Age = int(input("Enter your Age : ")) ; a.append(Age)
City = input("Enter your City : ") ; a.append(City)
Marks = int(input("Enter Marks : ")) ; a.append(Marks)
list.append(a)
stmt = "insert into result(RollNo,Name , Age ,City , Marks)values(%s,%s,%s,%s,%s)"
cursor.executemany(stmt,list)
mcon.commit( )
* * * Connectivity No. 2 * * *
def display_records( ) : Aim : write a program to show the
# Applying select query to a table . connectivity of SQL with Python
msql_select_query = "select * from result "
cursor.execute(msql_select_query)
records = cursor.fetchall( )
for col in records :
print(col[0],col[1],col[2],col[3],col[4])
#mcon.close( )
My database is “anand”
def finish( ) :
My password is “student” in my computer.
print("Thanks ! ! ! I quit ")
You must prepare the same in your system
before you try these programs
Later you can make changes as per your wish
#*****MAIN*******
choice = 0
import mysql.connector as msql
mcon = msql.connect(host='localhost', user='root',passwd='student',database='anand')
if mcon.is_connected( ) :
print("Successful connection to Mysql database")
ok = "create table result(RollNo integer, Name char(20), Age integer, City char(10), Marks integer);"
cursor.execute(ok) # Table is created here