You are on page 1of 28

ACTIVITY 1

PROBLEM STATEMENT

Write a program in python to get 2 numbers N1 and N2 from the user and perform all basic
mathematical operations i.e. +,-,*,/,//,% on these numbers.

Display the result as shown below-

Example Output-
Enter N1: 4
Enter N2: 3
4 + 3 = 12
4–3=1
4 * 3 = 12
4 / 3 = 1.3333
4//3 = 1
4%3 = 1

CODE

N1=int(input("Enter a number N1: "))


N2=int(input("Enter another number N2: "))
print("Performing all basic mathematic operations on numbers entered")
print(N1, " + ", N2 , " = ",N1+N2)
print(N1, " - ", N2 , " = ",N1-N2)
print(N1, " * ", N2 , " = ",N1*N2)
print(N1, " / ", N2 , " = ",N1/N2)
print(N1, " // ", N2 , " = ",N1//N2)
print(N1, " % ", N2 , " = ",N1%N2)
print("Thanks") ""

OUTPUT

<To be written or printed and pasted after execution by the student>

<><><><>><><>
ACTIVITY 2
PROBLEM STATEMENT

Write a program in python to print mathematical table of number N. Display T terms of table where
N and T is entered by user.

Example output—
Enter N : 4
Enter T : 5
5 Terms of Table of 4—
4X1=4
4X2=8
4 X 3 = 12
4 X 4 = 16

CODE

N=int(input("Enter the value of N: "))


T=int(input("Enter the value of T: "))
print(T, "Terms of ", N ," :-")
for I in range(1,T+1):
print(N , " X " , I , " = ", N*I)
print("Thanks")

OUTPUT

<To be written or printed and pasted after execution by the student>

<><><><>><><>
ACTIVITY 3
PROBLEM STATEMENT

Write a program in python to get a string from user and print the statistic as below-
Total No. of characters in String –
Number of letters –
Number of Uppercase letters –
Number of lowercase letters –
Number of Digits—
Number of Spaces--
Number of Special Characters—

CODE

STR=input("Enter any string: ")


COUNT_U=0
COUNT_L=0
COUNT_D=0
COUNT_S=0
for C in STR:
if C.isupper():
COUNT_U+=1
if C.islower():
COUNT_L+=1
if C.isdigit():
COUNT_D+=1
if C.isspace():
COUNT_S+=1
SPL_CHR = len(STR) - COUNT_U - COUNT_L - COUNT_D - COUNT_S
print("Total No. of characters in String: ", len(STR))
print("Number of letters in given string: ", COUNT_U + COUNT_L)
print("Number of uppercase letters in given string: ",COUNT_U)
print("Number of lowercase letters in given string: ",COUNT_L)
print("Number of digits in given string: ",COUNT_D)
print("Number of spaces in given string: ",COUNT_S)
print("Number of special characters in given string: ",SPL_CHR )
print("THANKS")

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
ACTIVITY 4
PROBLEM STATEMENT

Write a program in python to get a list of numbers L from user and do the following on the list-
1. Display all elements of list on screen separated by #.
2. Display 2nd last element of list on screen
3. Add 10 to first element of list
4. Delete 2nd element of list
5. Sort the list in decreasing order and display it.

CODE

L=eval(input("Enter a list of numbers: "))


for i in L:
print(i,end='#') #Display elements of list on screen separated by #.
print()
print("Displaying 2nd Last Element of List:")
print(L[-2]) #Display 2nd last element of list
print("Adding 10 to 1st element of list")
L[0] = L[0] + 10 #Add 10 to first element of list
print("Now list is: ", L)
print("Deleting 2nd element of list")
del L[1] #Delete 2nd element of list
print("Now list is: ", L)
print("Sorting list in decreasing order")
L.sort(reverse=True)
print("Now list is: ", L)

OUTPUT

<To be written or printed and pasted after execution by the student>

<><><><>><><>
ACTIVITY 5
PROBLEM STATEMENT

Write a function FACT(N) to find factorial of a number N. Now Use this function to calculate factorial
of any number entered by user.

CODE

def FACT(N):
f = 1
for i in range(N,1,-1):
f = f*i
print("Factorial of ",N," is :",f)

NUM = int(input("Enter any number to calculate factorial:"))


FACT(NUM)

OUTPUT

<To be written or printed and pasted after execution by the student>

<><><><>><><>
ACTIVITY 6
PROBLEM STATEMENT

Write a Function SimpleInterest() and show the usage of –


• Positional Arguments
• Default Arguments
• Keyword Arguments
CODE

def SimpleInterest(P , T , R=10):


I = P*T*R/100
print("Principal amount = ", P)
print("Time = ", T)
print("Rate of Inetrest = ", R)
print("Intrest = ", I)

Princ = 100
Time = 2
Rate = 12
print("Using Positional Function Arguments")
SimpleInterest(Princ,Time,Rate)
print("Using Default Function Arguments")
SimpleInterest(Princ,Time)
print("Using Keyword Function Arguments")
SimpleInterest(R = Rate, P = 1000,T = 3)

OUTPUT

<To be written or printed and pasted after execution by the student>

<><><><>><><>
ACTIVITY 7
PROBLEM STATEMENT

Write a program to open a file student.txt in different file modes. Check whether
file is opened or not in each case.
Hint: use <FileHandle>.closed to check if file is open or closed.

CODE

#Program to show different file opening modes for text file.


print("Opening an existing file in read only mode without specifying any
mode")
F = open("student.txt")
if not F.closed:
print("File Opened in Read Only mode ")
F.close()
print("Opening an existing file in read only mode using 'r'")
F = open("student.txt",'r')
if not F.closed:
print("File Opened Read Only mode ")
F.close()
print("Opening a file(does not exist already) in write only mode using 'w'")
F = open("student11.txt",'w')
if not F.closed:
print("File Opened in write only mode ")
F.close()
print("Opening a file(that exists already) in write mode using 'w'")
F = open("student11.txt",'w')
if not F.closed:
print("File Opened in write only mode ")
F.close()
print("Opening a file(that exists already) in appemd mode using 'a'")
F = open("student11.txt",'a')
if not F.closed:
print("File Opened in append mode ")
F.close()
OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
ACTIVITY 8

PROBLEM STATEMENT

Write a Program to read any text file and display its content as each word
separated by “ # “ symbol.

CODE

#Program to read content of file


#and display each word separated by '#'
f = open("file1.txt")
data = f.read()
for C in data:
print(C+'#',end='')
f.close()

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
ACTIVITY 9

PROBLEM STATEMENT

Write a Program to read the content of file and display the following-
Total number of characters in file:
Total number of digits in file:
Total number of vowels in file:
Total number of consonants in file:
Total number of uppercase letters:
Total number of lower case letters:

CODE

#Program to read content of file


#and display total number of vowels,
#consonants, lowercase and uppercase characters

f = open("file1.txt")
v=0
c=0
u=0
l=0
d=0
o=0
data = f.read()
vowels=['a','e','i','o','u']
for ch in data:
if ch.isalpha():
if ch.lower() in vowels:
v+=1
else:
c+=1
if ch.isupper():
u+=1
elif ch.islower():
l+=1
elif ch.isdigit():
d=d+1
elif ch!=' ' and ch!='\n':
o+=1
print("Total number of characters in file: ",len(data))
print("Total number of digits in file: ",d)
print("Total Vowels in file :",v)
print("Total Consonants in file :",c)
print("Total number of uppercase letters:",u)
print("Total number of lower case letters:",l)
f.close()

OUTPUT

<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 10

PROBLEM STATEMENT

Write Program to read the content of file line by line and write its content to
another file except for the lines that contains “*‟ character in it.

CODE

#Write Program to read the content of file line by line and


#write its content to another
#file except for the lines that contains “*‟ character in it

F1 = open("source.txt")
F2 = open("target.txt","w")
#Reading from the source file line by line
for Line in F1:
if '*' not in Line:
#Writing into target file
F2.write(Line)
F1.close()
F2.close()

OUTPUT

<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 11

PROBLEM STATEMENT

Write a program to Read a text file and count the number of times words ‘He’
and ‘She’ found in the file. Ignore the capital casing of letters (i.e. also count he,
she, HE, SHE etc.).

CODE

#Program to count words in a file


F = open("INPUT.txt") #opening file
COUNT=0
Data = F.read() #Reading all data from file
LW = Data.split() #Split into list of words
for W in LW:
if W.lower() in ['he','she']:
COUNT = COUNT+1
print("No. of times word 'He' or 'She' occured:",COUNT)
print("End of Program")

OUTPUT

<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 12

PROBLEM STATEMENT

Write a program to create a CSV file MARKS.csv after getting RollNo. , Name and
Marks of 10 students.

Now read this CSV file and print RollNo. and Name of those student who score
more than 90 marks.

CODE

#Program to create and read CSV file


import csv
#Opening File for Writing
F = open("MARKS.csv","w",newline='')
#Now creating writer object
FW = csv.writer(F)
#Getting details of students
for i in range(10):
print("Getting Details of Student ",i+1)
RNO = input("Enter Roll No: ")
NAME = input("Enter Name: ")
MARKS = input("Enter Marks: ")
FW.writerow([RNO,NAME,MARKS]) #Writing into file
F.flush() #To forcefully flush data into file
F.close()
F = open("MARKS.csv","r") #Open for reading
FR = csv.reader(F) #create reader object
print("Showing RollNo. and Name of Students having more than 90 marks")
for R in FR:
if int(R[2]) > 90:
print(R[0],R[1])
F.close()
print("End of Program")
OUTPUT

<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 13
PROBLEM STATEMENT

Write a Program to create a binary file to store Rollno and Name of students.
Then Search any Rollno and display name if Rollno is found, otherwise display -
“Rollno not found”

CODE

#Program to create a binary file to store Rollno and name


#Search for Rollno and display record if found
#otherwise "Roll no. not found"
import pickle
F=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
data = [roll,name]
pickle.dump(data,F)
ans=input("Add More ?(Y)")
F.close()

F=open('student.dat','rb')
r = int(input("Enter Roll number to search :"))
while True:
try:
data = pickle.load(F)
if data[0]==r:
print("Record Found, Name is :",data[1])
break
except EOFError:
print("NOT FOUND")
break
F.close()
OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 14

PROBLEM STATEMENT

Program to create binary file to store Rollno,Name and Marks and update marks of
entered Rollno.
CODE
#Program to create a binary file to store
#Rollno and name and then update it
import pickle
F=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
marks = int(input("Enter Marks :"))
data = [roll,name,marks]
pickle.dump(data,F)
ans=input("Add More ?(Y)")
F.close()
F=open('student.dat','rb+')
r = int(input("Enter Roll number to update :"))
n = int(input("Enter new Marks :"))
while True:
try:
POS = F.tell()
data = pickle.load(F)
if data[0]==r:
data[2] = n
F.seek(POS,0)
pickle.dump(data,F)
print("Record Updated")
break
except EOFError:
print("NOT FOUND")
break
F.close()
OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 15
PROBLEM STATEMENT

Write a Python program to implement a stack data-structure using a


list.

CODE

#Implementation of Stack using List


# Function to push elements into stack
def Push(stk,item):
stk.append(item)
top=len(stk)-1

def Pop(stk):
if stk==[]:
print("Stack Underflow")
else:
item=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)
print("Popped item is "+str(item))

def Display(stk):
if stk==[]:
print("Stack is empty")
else:
top=len(stk)-1
print("Elements in the stack are: ")
for i in range(top,-1,-1):
print (stk[i])

# Main

STACK=[]
while True:
print("STACK OPERATIONS")
print("1 : PUSH")
print("2 : POP")
print("3 : DISPLAY")
print("0 : EXIT")
op = input("Enter Your Choice: ")
if op == '0':
break
elif op == '1':
ITEM = input("Enter Item: ")
Push(STACK,ITEM)
elif op == '2':
Pop(STACK)
elif op == '3':
Display(STACK)
else:
print("Invalid Choice, Try Again! ")
OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 16

PROBLEM STATEMENT

Write SQL commands using MySQL for the following tasks—


(i) Create a database named KVK_2022 and connect to it.
(ii) Create a table DEPARTMENT as per details given below-
COLUMN NAME DEPT_ID DEPT_NAME
DATA TYPE Text(10) Text(100 Characters)
CONSTRAINT Primary Key NOT NULL
(iii) Create a table STUDENT as per the details given below-

COLUMN UID NAME CLASS GENDER DOB AdharID DEPT_ID


NAME
DATA Small Text (100 Small Number 1 Char Date Number TEXT(10)
TYPE Number chars)
CONSTRA Primary NOT Allowed Value of class UNIQUE Foreign Key refers
INT Key NULL should be between 1 Key DEPT_ID OF
and 12 only. DEPARTMENT table

(iv) Change data type of STUDENT.NAME column to Text of size 200 characters
(v) Add a new columns in table STUDENT as per below detail
Column Name Data Type
SECTION 1 Character
Fee Decimal
(vi) Display the structure of table on screen.
(vii) Delete column SECTION from STUDENT table

CODE
(i) CREATE DATABASE KVK_2022;
USE KVK_2022;
(ii) CREATE TABLE DEPARTMENT (
DEPT_ID VARCHAR(10) PRIMARY KEY,
DEPT_NAME VARCHAR(100) NOT NULL);
(iii) CREATE TABLE STUDENT (
UID INT PRIMARY KEY,
NAME VARCHAR(100) NOT NULL,
CLASS INT CHECK(CLASS >=1 OR CLASS <=12),
GENDER CHAR(1),
DOB DATE,
ADHARID INT UNIQUE,
DEPT_ID VARCHAR(10) REFERENCES DEPARTMENT(DEPT_ID) );
(iv) ALTER TABLE STUDENT MODIFY NAME VARCHAR(200);
(v) ALTER TABLE STUDENT ADD ( SECTION CHAR(1), FEE DECIMAL);
(vi) DESC STUDENT;
(vii) ALTER TABLE STUDENT DROP SECTION;

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 17

PROBLEM STATEMENT

Write SQL commands using MySQL for the following tasks—


(i) To insert following data in DEPARTMENT AND STUDENT table.
DEPARTMENT TABLE:
DEPT_ID DEPT_NAME
HUM Humanities
SCI Science
COM Commerce
STUDENT TABLE:
UID NAME CLASS GENDER DOB AdharID DEPT_ID FEE
101 Joya 12 F 12-01-2005 1201 HUM 1000
102 Suresh 12 M 09-08-2006 1202 SCI 3000
103 Mahesh 11 M 09-09-2007 1203 COM 2000
104 Aman 12 M 19-10-2006 SCI 3000
105 Priyanka 12 F 15-01-2005 COM 2000
106 Sheena 11 F 29-05-2006 1206 HUM 1000
107 Pankaj 11 M 24-09-2007 1207 SCI 3000
108 Tarun 11 M 17-04-2007 COM 2000
(ii) To update AdharID of student having UID 104 from NULL to 1204
(iii) To increase fee of Humanities students by 500 rupees.
(iv) To delete record of student having UID 108

CODE
(i) INSERT INTO DEPARTMENT VALUES ('HUM','Humanities');
INSERT INTO DEPARTMENT VALUES ('SCI','Science');
INSERT INTO DEPARTMENT VALUES ('COM','Commerce');
INSERT INTO STUDENT VALUES(101 ,'Joya' ,12 ,'F' ,'20050112'
,1201 ,'HUM' ,1000);
INSERT INTO STUDENT VALUES(102 ,'Suresh' ,12 ,'M' ,'20060809'
,1202 ,'SCI' ,3000);
INSERT INTO STUDENT VALUES(103 ,'Mahesh' ,11 ,'M' ,'20070909'
,1203 ,'COM' ,2000);
INSERT INTO STUDENT VALUES(104 ,'Aman' ,12 ,'M' ,'20061019'
, NULL ,'SCI' ,3000);
INSERT INTO STUDENT VALUES(105 ,'Priyanka' ,12 ,'F'
,'20050115' , NULL ,'COM' ,2000);
INSERT INTO STUDENT VALUES(106 ,'Sheena' ,11 ,'F' ,'20060529'
,1206 ,'HUM' ,1000);
INSERT INTO STUDENT VALUES(107 ,'Pankaj' ,11 ,'M' ,'20070924'
,1207 ,'SCI' ,3000);
INSERT INTO STUDENT VALUES(108 ,'Tarun' ,11 ,'M' ,'20070417'
, NULL ,'COM' ,2000);
(ii) UPDATE STUDENT SET ADHARID = 1204 WHERE UID = 104;
(iii) UPDATE STUDENT SET FEE = FEE + 500 WHERE DEPT_ID = ‘HUM’
(iv) DELETE FROM STUDENT WHERE UID = 108;

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 18

PROBLEM STATEMENT

Write SQL commands using MySQL for the following tasks—


(i) To display all data from student table.
(ii) To display only UID and Name of all students.
(iii) To display Name and Class of only girl students.
(iv) To display Fee of SCI students increased by 20% (use column alias also)
(v) To display details of boy students of class 12.
(vi) To display UID, Name and AdharID of students whose UID falls between 102 and 106
(vii) To display details of Boy whose name starts with letter ‘P’
(viii) To display details of class 11 students whose 2nd character of name is letter ‘a’
(ix) To display details of students whose AdharID is null.
(x) To display details of students whose AdharID is available?
(xi) To display the details of students in decreasing order of UID
(xii) To display different values in Dept_ID column.

CODE
(i) SELECT * FROM STUDENT;
(ii) SELECT UID, NAME FROM STUDENT;
(iii) SELECT NAME, CLASS FROM STUDENT WHERE GENDER = 'F';
(iv) SELECT FEE + FEE*0.20 AS 'NEW FEE' FROM STUDENT WHERE DEPT_ID =
'SCI';
(v) SELECT * FROM STUDENT WHERE GENDER = 'M' AND CLASS = '12';
(vi) SELECT UID,NAME, ADHARID FROM STUDENT WHERE UID BETWEEN 102 AND
106;
OR
SELECT UID,NAME, ADHARID FROM STUDENT WHERE UID >= 102 AND UID <=
106;
(vii) SELECT UID,NAME, ADHARID FROM STUDENT WHERE UID BETWEEN 102 AND
106;
(viii) SELECT * FROM STUDENT WHERE CLASS = 11 AND NAME LIKE '_a%';
(ix) SELECT * FROM STUDENT WHERE ADHARID IS NULL;
(x) SELECT * FROM STUDENT WHERE ADHARID IS NOT NULL;
(xi) SELECT * FROM STUDENT ORDER BY UID DESC;
(xii) SELECT DISTINCT DEPT_ID FROM STUDENT;
OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 19

PROBLEM STATEMENT

Write SQL commands using MySQL for the following tasks—


(i) To display total fee of all students in student table.
(ii) To display average fee of girl students in student table.
(iii) To display number of boy students in class 12.
(iv) To display number of girl students of class 12 who’s AdharID is not available.
(v) To display DOB of youngest and oldest student in student table.
(vi) To display minimum and maximum fee of girl students.
(vii) To display department wise number of students.
(viii) To display total fee of boys and girls separately.
(ix) To display gender wise minimum and maximum fee.
(x) To display Dept_ID in which there are more than 2 students

CODE
(i) SELECT SUM(FEE) FROM STUDENT;
(ii) SELECT AVG(FEE) FROM STUDENT WHERE GENDER='F';
(iii) SELECT COUNT(*) FROM STUDENT WHERE GENDER='M';
(iv) SELECT COUNT(*) FROM STUDENT WHERE GENDER='F' AND ADHARID IS
NULL;
(v) SELECT MAX(DOB), MIN(DOB) FROM STUDENT;
(vi) SELECT MAX(FEE), MIN(FEE) FROM STUDENT WHERE GENDER='F';
(vii) SELECT DEPT_ID, COUNT(*) FROM STUDENT GROUP BY DEPT_ID;
(viii) SELECT GENDER, SUM(FEE) FROM STUDENT GROUP BY GENDER;
(ix) SELECT GENDER, MAX(FEE),MIN(FEE) FROM STUDENT GROUP BY GENDER;
(x) SELECT DEPT_ID, COUNT(*) FROM STUDENT GROUP BY DEPT_ID HAVING
COUNT(*) >2;

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 20

PROBLEM STATEMENT

Write SQL commands using MySQL for the following tasks—


(i) To display Student Name and Department Name of all class 12 students.
(ii) To display UID, Student Name, Department Name and Fee of girl students of class 11.
(iii) To display UID. Student Name and Department Name details of those students whose department
name ends with letter ‘e’

CODE
(i) SELECT S.NAME, D.DEPT_NAME FROM STUDENT S, DEPARTMENT D WHERE
S.DEPT_ID = D.DEPT_ID;
(ii) SELECT S.UID, S.NAME, S.FEE, D.DEPT_NAME FROM STUDENT S,
DEPARTMENT D WHERE S.DEPT_ID = D.DEPT_ID AND S.GENDER='F';
(iii) SELECT S.UID, S.NAME, D.DEPT_NAME FROM STUDENT S, DEPARTMENT D
WHERE S.DEPT_ID = D.DEPT_ID AND D.DEPT_NAME LIKE '%e';

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 21

PROBLEM STATEMENT

Write a program in python to connect to database KVK_2022 created in activity 16.


Check whether the connection was successful or not. If successfully connected, display
“Connected” otherwise display “Could not connect”

CODE
import mysql.connector as sql
try:
CON = sql.connect(host="localhost", user="root",passwd="mysql",
database="KVK_2022")

if CON.is_connected():
print("Connected")
else:
print("Could not Connect")
except:
print("Could not Connect")

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 22

PROBLEM STATEMENT

Write a Python program to get details of 5 students and insert it into Student table created in Activity 16.
Structure of table is –

UID NAME CLASS GENDER DOB AdharID DEPT_ID FEE

CODE
import mysql.connector as sql
CON = sql.connect(host="localhost", user="root",passwd="mysql",
database="KVK_2022")
CUR=CON.cursor()
for i in range(5):
print("Getting Details of Student ",i+1)
UID = int(input("Enter UID: "))
NAME = input("Enter Name: ")
CLASS = input("Enter Class: ")
GENDER = input("Enter Gender: ")
DOB = input("Enter DOB(YYYYMMDD): ")
ADHAR = int(input("Enter Adhar ID: "))
DEPT= input("Enter Dept ID: ")
FEE = float(input("Enter Fee: "))
QUERY = f'''INSERT INTO STUDENT VALUES (
{UID}, '{NAME}', '{CLASS}','{GENDER}','{DOB}',{ADHAR},
'{DEPT}', {FEE})'''
CUR.execute(QUERY)
CUR.execute("COMMIT")
print("Record Inserted")
CON.close()

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 23

PROBLEM STATEMENT

PWrite a Python program to update the fee of any student based upon the UID entered
by user.

CODE

import mysql.connector as sql


CON = sql.connect(host="localhost", user="root",passwd="mysql",
database="KVK_2022")
CUR=CON.cursor()
U = int(input("Enter UID: "))
F = float(input("Enter New Fee: "))
QUERY = f"UPDATE STUDENT SET FEE = {F} WHERE UID = {U}"
CUR.execute(QUERY)
CUR.execute("COMMIT")
print("Record UPDATED")
CON.close()

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>
PROGRAM 24

PROBLEM STATEMENT

Write a Python program to display the details of student whose name is entered by
user.

CODE
import mysql.connector as sql
CON = sql.connect(host="localhost", user="root",passwd="mysql",
database="KVK_2022")
CUR=CON.cursor()
N = input("Enter Name :")
QUERY = f"SELECT * FROM STUDENT WHERE NAME LIKE '%{N}%'"
CUR.execute(QUERY)
DATA = CUR.fetchall()
for I in DATA:
print(I)
CON.close()

OUTPUT
<To be written or printed and pasted after execution by the student>

<><><><>><><>

You might also like