SlideShare a Scribd company logo
COMPUTER SCIENCE
PRACTICAL FILE
ON
PYTHON PROGRAMS & MYSQL
Submitted by: Submitted to:
Rishabh Rawat Mr. Manish Bhatt
Roll No.-
INDEX
Q1. WAP to input a year and check whether the year is leap year or not.
Q2. WAP to input 3 numbers and print the greatest number using nested
if.
Q3. WAP to input value of x and n and print the series along with its sum.
Q4. WAP to input a number and check whether it is prime number or
not.
Q5. WAP to print fibonacci series upto n terms, also find sum of series.
Q6. WAP to print the given patterns.
Q7. WAP to print a string and the number of vowels present in it.
Q8. Write a program to read a file story.txt and print the contents of file
along with number of vowels present in it.
Q9. Write a program to read a file book.txt print the contents of file
along with numbers of words and frequency of word computer in it.
Q10. Write a program to read a file Top.txt and print the contents of file
along with the number of lines starting with A.
Q11. WAP to input a list of number and search for a given number using
linear search.
Q12. WAP to input a list of integers and search for a given number using
binary search.
Q13. Write a function DigitSum() that takes a number and returns its
digit sum.
Q14. Write a function Div3and5() that takes a 10 elements numeric tuple
and return the sum of elements which are divisible by 3 and 5.
Q15. Write a recursive function ChkPrime() that checks a number for
Prime.
Q16. Write a function to input a list and arrange the list in ascending
order using Bubble sort.
Q17. Write a menu based program to demonstrate operation on a stack.
Q18. Write a menu based program to demonstrate operations on queue.
Q19. MySQL Queries
Q20. Python –MYSQL Connectivity
1. # WAP toinput a year and check whether the year is leapyear or not
y=int(input("Enter the year: "))
if y%400==0:
print("Theyear is a Century Leap Year")
elif y%100!=0 and y%4==0:
print("Year is a Leap year")
else:
print("Year is not a leap year")
Enter the year:2000
The year is a Century LeapYear
2. #WAP to input 3 numbers and print the greatest number using nestedif
a=float(input("Enter the firstnumber: "))
b=float(input("Enter the second number: "))
c=float(input("Enter the third number: "))
if a>=b:
if a>=b:
print("Firstnumber :",a,"is greatest")
if b>a:
if b>c:
print("Second number :",b,"is greatest")
if c>a:
if c>b:
print("Third number :",c,"is greatest")
Enter the first number4
Enter the secondnumber2
Enter the thirdnumber2.1
First number : 4.0 is greatest
3.# WAP to input value of x and n and print the series along with its sum
x=float(input("Enter the value of x"))
n=float(input("Enter the value of n"))
i=1
s=0
while i<n:
y=x**i
print(y, "+", end='')
s=s+y
i+=1
print(x**n) #to print the last element of series
s=s+(x**n) #to add the last element of series
print("Sum of series =", s)
Enter the value of x4
Enter the value of n2
4.0 +16.0
Sum of series = 20.0
4.# WAP to input a number and check whether it is prime number or not
n=int(input("Enter the number"))
c=1
for i in range(2,n):
if n%i==0:
c=0
if c==1:
print("Number is prime")
else:
print("Number is not prime")
Enter the number29
Number is prime
5.#WAP to print fibonacci series uptonterms, alsofind sum of series
n=int(input("Enter the number of terms in fibonacci series"))
a,b=0,1
s=a+b
print(a,b,end=" ")
for i in range(n-2):
print(a+b,end=" ")
a,b=b,a+b
s=s+b
print()
print("Sum of",n,"terms of series =",s)
Enter the number of terms infibonacci series10
0 1 1 2 3 5 8 13 21 34
Sum of 10 terms of series =88
6. # WAP to print the patterns
#1 program to print pattern
for i in range(1,6):
for j in range(1,i+1):
print(j,end="")
print()
1
12
123
1234
12345
#2 program to print pattern
for i in range(5,0,-1):
for j in range(i):
print('*',end="")
print()
*****
****
***
**
*
7.#WAP to print a string and the number of vowels present init
st=input("Enter the string")
print("Entered string =",st)
st=st.lower()
c=0
v=['a','e','i','o','u']
for i in st:
if i in v:
c+=1
print("Number of vowels in entered string =",c)
Enter the stringI am a good boi
Enteredstring =I am a good boi
Number of vowels inenteredstring =7
8.#Write aprogram to reada file story.txt andprint the contents of file along with
number of vowels present init
f=open("story.txt",'r')
st=f.read()
print("Contents of file :")
print(st)
c=0
v=['a','e','i','o','u']
for i in st:
if i.lower() in v:
c=c+1
print("*****FILEEND*****")
print()
print("Number of vowels in the file =",c)
f.close()
Contents of file :
Python is an interpreted, high-level, general-purpose programming language.
Createdby Guido van Rossumand first releasedin1991.
Python's designphilosophy emphasizes code readability.
Its language constructs andobject-oriented approachaim to helpprogrammers write
clear, logical code.
*****FILE END*****
Number of vowels inthe file = 114
9.#Write a program to read a file book.txt print the contents of file along with numbers of
words and frequency of word computerin it
f=open("book.txt","r")
L=f.readlines()
c=c1=0
v=['a','e','i','o','u']
print("Contents of file :")
for i in L:
print(i)
j=i.split()
for k in j:
if k.lower()=="computer":
c1=c1+1
for x in k:
if x .lower() in v:
c+=1
print("*****FILE END*****")
print()
print("Number of vowels in the file =",c)
print("Number of times 'computer' in the file =",c1)
f.close()
Contents of file :
Python is an interpreted, high-level, general-purpose computerprogramming language.
Created by Guido van Rossum and first released in 1991.
Python's design philosophy emphasizes code readability.
Its language constructs and object-oriented approach aim to help programmers write clear,
logical code.
*****FILE END*****
Numberof vowels in the file = 92
Numberof times 'computer' in the file = 1
10. #Write a program to read a file Top.txt and print the contents of file along with the number of
lines starting with A
f=open("Top.txt","r")
st=f.readlines()
c=0
print("Contents of file:")
for i in st:
print(i)
if i[0]=="A":
c+=1
print("n*****FILE END*****")
print()
print("Number of lines starting with'A' =",c)
Contents of file :
Python is an interpreted, high-level, general-purposeprogramming language.
Created by Guido van Rossum and first released in 1991.
Python's design philosophy emphasizes code readability.
Its language constructs and object-oriented approach aim to help programmers write clear, logical
code.
*****FILE END*****
Number of lines starting with 'A' = 0
11.#WAP to input a list of number and search for a given number using linear search
l=eval(input("Enter thelist of numbers"))
x=int(input("Enter thenumber"))
for i in l:
if i==x:
print("ELement present")
break
else:
print("Element not found")
Enter the list of numbers[5,3,4,2,1]
Enter the number3
ELement present
12.#WAP to input a list of integers and search for a given number using binary search
def bsearch(L,n):
start=0
end=len(L)-1
whilestart<=end:
mid=(start+end)//2
if L[mid]==n:
return True
elif L[mid]<=n:
start=mid+1
else:
end=mid-1
else:
return False
L=eval(input("Enter thelist of numbers"))
n=int(input("Enter thenumber to find"))
L.sort()
if bsearch(L,n):
print("Element found")
else:
print("Element not found")
Enter the list of numbers[5,3,4,2,1]
Enter the number to find6
ELement not found
13.#Write afunctionDigitSum() that takes a number and returns its digit sum
def DigitSum(n):
s=0
n=str(n)
for i in n:
s=s+int(i)
return s
n=int(input("Enter the number"))
print("Sum of digits =",DigitSum(n))
Enter the number69
Sum of digits = 15
14.#Write afunctionDiv3and5() that takes a 10 elements numeric tuple andreturnthe
sum of elements whichare divisible by 3 and 5
def Div3and5(t):
s=0
for i in t:
if i%3==0 and i%5==0:
s=s+i
return s
#main
l=[]
for i in range(10):
print("Enter the ",i+1,"th number of the tuple",end=" ",sep="")
e=int(input())
l.append(e)
t=tuple(l)
print("Entered tuple :",t)
print("Sum of numbers in tuple divisible by 3 and 5 =",Div3and5(t))
Enter the 1th number of the tuple 3
Enter the 2th number of the tuple 2
Enter the 3th number of the tuple 5
Enter the 4th number of the tuple 10
Enter the 5th number of the tuple 15
Enter the 6th number of the tuple 20
Enter the 7th number of the tuple 30
Enter the 8th number of the tuple 2
Enter the 9th number of the tuple 67
Enter the 10th number of the tuple 50
Entered tuple : (3, 2, 5, 10, 15, 20, 30, 2, 67, 50)
Sum of numbers in tuple divisible by 3 and 5 = 45
15.#Write a recursive function ChkPrime() that checks a number for Prime
def ChkPrime(n,i):
whilei<n:
if n%i==0:
return False
else:
i+=1
ChkPrime(n,i)
return True
n=int(input("Enter thenumber"))
if ChkPrime(n,2):
print("Number is prime")
else:
print("Number ain't prime")
Enter the number23
Number is prime
16.#Write afunctiontoinput a list and arrange the list in ascending order using Bubble
sort
l=eval(input("Enter the list to arrange"))
for i in range(len(l)-1):
for j in range(len(l)-1):
if l[j]>l[j+1]:
l[j],l[j+1]=l[j+1],l[j]
print("Arranged list:",l)
Enter the list toarrange[5,4,2,3,0,1]
Arrangedlist :[0, 1, 2, 3, 4, 5]
17.#Write amenu basedprogram to demonstrate operationona stack
def isEmpty(stk):
if len(stk)==0:
return True
else:
return False
def push(stk,n):
stk.append(n)
def pop(stk):
if isEmpty(stk):
print("UNDERFLOW CONDITION")
else:
print("Deleted element:",stk.pop())
def peek(stk):
return stk[-1]
def display(stk):
if isEmpty(stk):
print("No Element Present")
else:
for i in range(-1,-len(stk)-1,-1):
if i==-1:
print("TOP",stk[i])
else:
print(" ",stk[i])
#main
stk=[]
while True:
print(" Stack operations")
print(" 1.PUSH")
print(" 2.POP")
print(" 3.PEEK")
print(" 4.DISPLAYSTACK")
print(" 5.EXIT")
ch=int(input(" Enter the choice"))
if ch==1:
n=input("Enter the element to PUSH")
push(stk,n)
print("Element pushed")
elif ch==2:
pop(stk)
elif ch==3:
if isEmpty(stk):
print("UNDERFLOW CONDITION")
else:
print(peek(stk))
elif ch==4:
display(stk)
elif ch==5:
break
else:
print("INVALIDCHOICEENTERED")
print("THANKS FOR USING MYSERVICES")
Stack operations
1.PUSH
2.POP
3.PEEK
4.DISPLAY STACK
5.EXIT
Enter the choice1
Enter the element toPUSH98
Element pushed
Stack operations
1.PUSH
2.POP
3.PEEK
4.DISPLAY STACK
5.EXIT
Enter the choice1
Enter the element toPUSH76
Element pushed
Stack operations
1.PUSH
2.POP
3.PEEK
4.DISPLAY STACK
5.EXIT
Enter the choice1
Enter the element to PUSH89
Element pushed
Stack operations
1.PUSH
2.POP
3.PEEK
4.DISPLAY STACK
5.EXIT
Enter the choice4
TOP 89
76
98
Stack operations
1.PUSH
2.POP
3.PEEK
4.DISPLAY STACK
5.EXIT
Enter the choice2
Deletedelement:89
Stack operations
1.PUSH
2.POP
3.PEEK
4.DISPLAY STACK
5.EXIT
Enter the choice4
TOP 76
98
18.#Write a menu basedprogram to demonstrate operationsonqueue
def isEmpty(qu):
if len(qu)==0:
return True
else:
return False
def ENQUEUE(qu,item):
qu.append(item)
if len(qu)==1:
rear=front=0
else:
rear=len(qu)-1
front=0
def DEQUEUE(qu):
if isEmpty(qu):
print("UNDERFLOW CONDITION")
else:
a= qu.pop(0)
print("ELEMENTDELETED:",a)
def peek(stk):
return stk[-1]
def display(qu):
if isEmpty(qu):
print("NO ELEMENT PRESENT")
else:
for i in range(len(qu)):
if i==0:
print("FRONT",qu[i])
elif i==len(qu)-1:
print("REAR",qu[i])
else:
print(" ",qu[i])
#main
qu=[]
while True:
print(“tt QUEUE OPERATIONS")
print("tt1.ENQUEUE")
print("tt2.DEQUEUE")
print("tt3.DISPLAYQUEUE")
print("tt4.PEEK")
print(“tt5.EXIT")
ch=int(input("ttEnter your choice: "))
if ch==1:
x=input("Enter the element to be inserted: ")
ENQUEUE(qu,x)
print("ELEMENTHAS BEEN INSERTED")
elif ch==2:
DEQUEUE(qu)
elif ch==3:
display(qu)
elif ch==4:
if isEmpty(qu):
print("UNDERFLOW CONDITION")
else:
print(peek(qu))
elif ch==5:
break
else:
print("INVALIDCHOICEENTERED")
print("THANKS FORUSING MYSERVICES")
QUEUE OPERATIONS
1.ENQUEUE
2.DEQUEUE
3.DISPLAY QUEUE
4.PEEK
5.EXIT
Enter your choice 1
Enter the element tobe inserted:Rishabh
ELEMENTHAS BEEN INSERTED
QUEUE OPERATIONS
1.ENQUEUE
2.DEQUEUE
3.DISPLAY QUEUE
4.PEEK
5.EXIT
Enter your choice 1
Enter the element tobe inserted:Python
ELEMENTHAS BEEN INSERTED
QUEUE OPERATIONS
1.ENQUEUE
2.DEQUEUE
3.DISPLAY QUEUE
4.PEEK
5.EXIT
Enter your choice 1
Enter the element tobe inserted:Selenium
ELEMENTHAS BEEN INSERTED
QUEUE OPERATIONS
1.ENQUEUE
2.DEQUEUE
3.DISPLAY QUEUE
4.PEEK
5.EXIT
Enter your choice 3
FRONTRishabh
Python
REAR Selenium
QUEUE OPERATIONS
1.ENQUEUE
2.DEQUEUE
3.DISPLAY QUEUE
4.PEEK
5.EXIT
Enter your choice 2
ELEMENTDELETED: Rishabh
QUEUE OPERATIONS
1.ENQUEUE
2.DEQUEUE
3.DISPLAY QUEUE
4.PEEK
5.EXIT
Enter your choice 3
FRONTPython
REAR Selenium
QUEUE OPERATIONS
1.ENQUEUE
2.DEQUEUE
3.DISPLAY QUEUE
4.PEEK
5.EXIT
Enter your choice 5
THANKS FOR USING MY SERVICES
20#Python –MYSQL Connectivity
import mysql.connector
def insert():
cur.execute("desc {}".format(table_name))
data=cur.fetchall()
full_input=""
for i in data:
print("NOTE: Pleaseenter string/varchar/datevalues (if any) in quotes")
print("Enter the",i[0],end=" ")
single_value=input()
full_input=full_input+single_value+","
full_input=full_input.rstrip(",")
cur.execute("Insertinto {} values({})".format(table_name,full_input))
mycon.commit()
print("Record successfully inserted")
def display():
n=int(input("Enter the number of records to display "))
cur.execute("Select * from{}".format(table_name))
for i in cur.fetchmany(n):
print(i)
def search():
find=input("Enter the column name using which you wantto find the record ")
print("Enter the",find,"of thatrecord",end=" ")
find_value=input()
cur.execute("select* from{} where {}='{}'".format(table_name,find,find_value))
print(cur.fetchall())
def modify():
mod=input("Enter the field name to modify ")
find=input("Enter the column name using which you wantto find the record ")
print("Enter the",find,"of thatrecord",end=" ")
find_value=input()
print("Enter the new",mod,end=" ")
mod_value=input()
cur.execute("update{} set {}='{}' where
{}='{}'".format(table_name,mod,mod_value,find,find_value))
mycon.commit()
print("Record sucessfully modified")
def delete():
find=input("Enter the column name using which you wantto find the recordnNOTE: NO
TWO RECORDS SHOULD HAVESAME VALUEFORTHIS COLUMN: ")
print("Enter the",find,"of thatrecord",end=" ")
find_value=input()
cur.execute("delete from {} where{}='{}'".format(table_name,find,find_value))
mycon.commit()
print("Record successfully deleted")
#__main__
database_name=input("Enter the database")
my_sql_password=input("Enter thepassword for MySQL ")
table_name=input("Enter the table name ")
mycon=mysql.connector.connect(host="localhost",user="root",database=database_name,p
asswd=my_sql_password)
cur=mycon.cursor()
if mycon.is_connected():
print("Successfully Connected to Database")
else:
print("Connection Faliled")
while True:
print("tt1. InsertRecord")
print("tt2. Display Record")
print("tt3. Search Record")
print("tt4. Modify Record")
print("tt5. Delete Recod")
print("tt6. Exitn")
ch=int(input("Enter the choice "))
if ch==1:
insert()
elif ch==2:
display()
elif ch==3:
search()
elif ch==4:
modify()
elif ch==5:
delete()
elif ch==6:
mycon.close()
break
else:
print("Invalid choiceentered")
Enter the database Rishabh
Enter the passwordfor MySQL CHUTIYA#1
Enter the table name EMP
Successfully ConnectedtoDatabase
1. Insert Record
2. Display Record
3. SearchRecord
4. Modify Record
5. Delete Recod
6. Exit
Enter the choice 1
NOTE: Please enter string/varchar/date values (if any) inquotes
Enter the EMPNO 120
NOTE: Please enter string/varchar/date values (if any) inquotes
Enter the EMPNAME"RishabhRawat"
NOTE: Please enter string/varchar/date values (if any) inquotes
Enter the DEPT "Computer"
NOTE: Please enter string/varchar/date values (if any) inquotes
Enter the DESIGN "Coder"
NOTE: Please enter string/varchar/date values (if any) inquotes
Enter the basic 100000
NOTE: Please enter string/varchar/date values (if any) inquotes
Enter the CITY "Srinagar"
Recordsuccessfully inserted
1. Insert Record
2. Display Record
3. SearchRecord
4. Modify Record
5. Delete Recod
6. Exit
Enter the choice 2
Enter the number of records todisplay 10
(111, 'AkashNarang', 'Account', 'Manager', 50000, 'Dehradun')
(112, 'Vijay Duneja', 'Sales', 'Clerk', 21000, 'lucknow')
(113, 'Kunal Bose', 'Computer', 'Programmer', 45000, 'Delhi')
(114, 'Ajay Rathor', 'Account', 'Clerk', 26000, 'Noida')
(115, 'Kiran Kukreja', 'Computer', 'Operator', 30000, 'Dehradun')
(116, 'PiyushSony', 'Sales', 'Manager', 55000, 'Noida')
(117, 'MakrandGupta', 'Account', 'Clerk', 16000, 'Delhi')
(118, 'HarishMakhija', 'Computer', 'Programmer', 34000, 'Noida')
(120, 'RishabhRawat', 'Computer', 'Coder', 100000, 'Srinagar')
1. Insert Record
2. Display Record
3. SearchRecord
4. Modify Record
5. Delete Recod
6. Exit
Enter the choice 3
Enter the column name using which you want tofind the recordEMPNO
Enter the EMPNO of that record120
[(120, 'RishabhRawat', 'Computer', 'Coder', 100000, 'Srinagar')]
1. Insert Record
2. Display Record
3. Search Record
4. Modify Record
5. Delete Recod
6. Exit
Enter the choice 4
Enter the fieldname to modify basic
Enter the column name using which you want tofind the recordEMPNAME
Enter the EMPNAMEof that recordRishabhRawat
Enter the new basic 200000
Recordsucessfully modified
1. Insert Record
2. Display Record
3. SearchRecord
4. Modify Record
5. Delete Recod
6. Exit
Enter the choice 5
Enter the column name using which you want tofind the record
NOTE: NO TWO RECORDS SHOULD HAVESAME VALUE FOR THIS COLUMN:EMPNO
Enter the EMPNO of that record120
Recordsuccessfully deleted
19. MySQL Queries
1. SELECT * FROM job;
2. SELECT jobtitle,salary FROM job;
3. SELECT * FROM job WHEREsalary>100000;
4. SELECT MAX(salary) FROM job;
5. SELECT COUNT(DISTINCTjobtitle) FROMjob;
6. SELECT * FROM job WHEREjobtitle LIKE“R%”
7. SELECT * FROM job ORDER BY salary ASC;
8. SELECT SUM(salary) AS “TOTAL SALARY”FROM job;
9. SELECT * FROM CLUB;
10. SELECT * FROM CLUB GROUP BY SPORTS;
11. SELECT * FROM EMP;
12. SELECT CITY,COUNT(*) FROM EMP GROUP BY CITY HAVING COUNT(*)>1;
13. SELECT DEPT,SUM(basic) AS “TOTAL SALARY”FROM EMP GROUP BY DEPT;
14. SELECT * FROM GROUP BY CITY HAVING basic>30000;
15. SELECT * FROM WHERECITY=”Noida” ORDER BY basic ASC;
Ad

Recommended

Computer Science Practical File class XII
Computer Science Practical File class XII
YugenJarwal
 
COMPUTER SCIENCE INVESTIGATORY PROJECT ON FOOTBALL GAME AND SCORE MANAGEMENT ...
COMPUTER SCIENCE INVESTIGATORY PROJECT ON FOOTBALL GAME AND SCORE MANAGEMENT ...
pankajkumbara
 
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...
ArkaSarkar23
 
Ip library management project
Ip library management project
AmazShopzone
 
Computer science project on Online Banking System class 12
Computer science project on Online Banking System class 12
OmRanjan2
 
12th CBSE Computer Science Project
12th CBSE Computer Science Project
Ashwin Francis
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
computer science with python project for class 12 cbse
computer science with python project for class 12 cbse
manishjain598
 
Computer science Project for class 11th and 12th(library management system)
Computer science Project for class 11th and 12th(library management system)
lokesh meena
 
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
SHAJUS5
 
Computer project final for class 12 Students
Computer project final for class 12 Students
Shahban Ali
 
Computer Project for class 12 CBSE on school management
Computer Project for class 12 CBSE on school management
RemaDeosiSundi
 
Looping statement in python
Looping statement in python
RaginiJain21
 
Computer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market Billing
Harsh Kumar
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12
Self-employed
 
Employee Management (CS Project for 12th CBSE)
Employee Management (CS Project for 12th CBSE)
PiyushKashyap54
 
TO STUDY THE QUANTITY OF CASEIN PRESENT IN DIFFERENT SAMPLES OF MILK
TO STUDY THE QUANTITY OF CASEIN PRESENT IN DIFFERENT SAMPLES OF MILK
AnkitSharma1903
 
Chapter 02 functions -class xii
Chapter 02 functions -class xii
Praveen M Jigajinni
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
Anushka Rai
 
Physics activity file class 12
Physics activity file class 12
Titiksha Sharma
 
Physics Investigatory Project Class 12
Physics Investigatory Project Class 12
Self-employed
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
KiranKumari204016
 
Maths practical file (class 12)
Maths practical file (class 12)
Anushka Rai
 
Computer science project.pdf
Computer science project.pdf
HarshitSachdeva17
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
HIMANSHU .
 
Python and MySQL Linking Class 12th Project File 23-24
Python and MySQL Linking Class 12th Project File 23-24
Akshat Singh
 
chemistry.pdf
chemistry.pdf
AradhyaAgrawal5
 
PREPARATION OF SOYBEAN MILK AND ITS COMPARISION WITH NATURAL MILK
PREPARATION OF SOYBEAN MILK AND ITS COMPARISION WITH NATURAL MILK
RajivSingh261
 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
jeyel85227
 
Sample Program file class 11.pdf
Sample Program file class 11.pdf
YashMirge2
 

More Related Content

What's hot (20)

Computer science Project for class 11th and 12th(library management system)
Computer science Project for class 11th and 12th(library management system)
lokesh meena
 
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
SHAJUS5
 
Computer project final for class 12 Students
Computer project final for class 12 Students
Shahban Ali
 
Computer Project for class 12 CBSE on school management
Computer Project for class 12 CBSE on school management
RemaDeosiSundi
 
Looping statement in python
Looping statement in python
RaginiJain21
 
Computer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market Billing
Harsh Kumar
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12
Self-employed
 
Employee Management (CS Project for 12th CBSE)
Employee Management (CS Project for 12th CBSE)
PiyushKashyap54
 
TO STUDY THE QUANTITY OF CASEIN PRESENT IN DIFFERENT SAMPLES OF MILK
TO STUDY THE QUANTITY OF CASEIN PRESENT IN DIFFERENT SAMPLES OF MILK
AnkitSharma1903
 
Chapter 02 functions -class xii
Chapter 02 functions -class xii
Praveen M Jigajinni
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
Anushka Rai
 
Physics activity file class 12
Physics activity file class 12
Titiksha Sharma
 
Physics Investigatory Project Class 12
Physics Investigatory Project Class 12
Self-employed
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
KiranKumari204016
 
Maths practical file (class 12)
Maths practical file (class 12)
Anushka Rai
 
Computer science project.pdf
Computer science project.pdf
HarshitSachdeva17
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
HIMANSHU .
 
Python and MySQL Linking Class 12th Project File 23-24
Python and MySQL Linking Class 12th Project File 23-24
Akshat Singh
 
chemistry.pdf
chemistry.pdf
AradhyaAgrawal5
 
PREPARATION OF SOYBEAN MILK AND ITS COMPARISION WITH NATURAL MILK
PREPARATION OF SOYBEAN MILK AND ITS COMPARISION WITH NATURAL MILK
RajivSingh261
 
Computer science Project for class 11th and 12th(library management system)
Computer science Project for class 11th and 12th(library management system)
lokesh meena
 
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
SHAJUS5
 
Computer project final for class 12 Students
Computer project final for class 12 Students
Shahban Ali
 
Computer Project for class 12 CBSE on school management
Computer Project for class 12 CBSE on school management
RemaDeosiSundi
 
Looping statement in python
Looping statement in python
RaginiJain21
 
Computer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market Billing
Harsh Kumar
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12
Self-employed
 
Employee Management (CS Project for 12th CBSE)
Employee Management (CS Project for 12th CBSE)
PiyushKashyap54
 
TO STUDY THE QUANTITY OF CASEIN PRESENT IN DIFFERENT SAMPLES OF MILK
TO STUDY THE QUANTITY OF CASEIN PRESENT IN DIFFERENT SAMPLES OF MILK
AnkitSharma1903
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
Anushka Rai
 
Physics activity file class 12
Physics activity file class 12
Titiksha Sharma
 
Physics Investigatory Project Class 12
Physics Investigatory Project Class 12
Self-employed
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
KiranKumari204016
 
Maths practical file (class 12)
Maths practical file (class 12)
Anushka Rai
 
Computer science project.pdf
Computer science project.pdf
HarshitSachdeva17
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
HIMANSHU .
 
Python and MySQL Linking Class 12th Project File 23-24
Python and MySQL Linking Class 12th Project File 23-24
Akshat Singh
 
PREPARATION OF SOYBEAN MILK AND ITS COMPARISION WITH NATURAL MILK
PREPARATION OF SOYBEAN MILK AND ITS COMPARISION WITH NATURAL MILK
RajivSingh261
 

Similar to CBSE Class 12 Computer practical Python Programs and MYSQL (20)

ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
jeyel85227
 
Sample Program file class 11.pdf
Sample Program file class 11.pdf
YashMirge2
 
xii cs practicals
xii cs practicals
JaswinderKaurSarao
 
Python.pptx
Python.pptx
AshaS74
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
python lab programs.pdf
python lab programs.pdf
CBJWorld
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Introduction to phyton , important topic
Introduction to phyton , important topic
akpgenious67
 
Python lab manual all the experiments are available
Python lab manual all the experiments are available
Nitesh Dubey
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Mohamed Abdallah
 
xii cs practicals class 12 computer science.pdf
xii cs practicals class 12 computer science.pdf
gmaiihghtg
 
Loops in Python
Loops in Python
Arockia Abins
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
datastructure-1 lab manual journals practical
datastructure-1 lab manual journals practical
AlameluIyer3
 
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
anuragupadhyay0537
 
Python programs
Python programs
yerra.vakula
 
Sasin nisar
Sasin nisar
SasinNisar
 
computer science file (python)
computer science file (python)
aashish kumar
 
Python 101 1
Python 101 1
Iccha Sethi
 
Sample-Program-file-with-output-and-index.docx
Sample-Program-file-with-output-and-index.docx
hariharasudan456
 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
jeyel85227
 
Sample Program file class 11.pdf
Sample Program file class 11.pdf
YashMirge2
 
Python.pptx
Python.pptx
AshaS74
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
python lab programs.pdf
python lab programs.pdf
CBJWorld
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Introduction to phyton , important topic
Introduction to phyton , important topic
akpgenious67
 
Python lab manual all the experiments are available
Python lab manual all the experiments are available
Nitesh Dubey
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Mohamed Abdallah
 
xii cs practicals class 12 computer science.pdf
xii cs practicals class 12 computer science.pdf
gmaiihghtg
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
rajatxyz
 
datastructure-1 lab manual journals practical
datastructure-1 lab manual journals practical
AlameluIyer3
 
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
678676286-CLASS-12-COMPUTER-SCIENCE-PRACTICAL-FILE-2023-24.pdf
anuragupadhyay0537
 
computer science file (python)
computer science file (python)
aashish kumar
 
Sample-Program-file-with-output-and-index.docx
Sample-Program-file-with-output-and-index.docx
hariharasudan456
 
Ad

Recently uploaded (20)

Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Rajdeep Bavaliya
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Tanja Vujicic - PISA for Schools contact Info
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Gladiolous Cultivation practices by AKL.pdf
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
Photo chemistry Power Point Presentation
Photo chemistry Power Point Presentation
mprpgcwa2024
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Rajdeep Bavaliya
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Tanja Vujicic - PISA for Schools contact Info
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Gladiolous Cultivation practices by AKL.pdf
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
Photo chemistry Power Point Presentation
Photo chemistry Power Point Presentation
mprpgcwa2024
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Ad

CBSE Class 12 Computer practical Python Programs and MYSQL

  • 1. COMPUTER SCIENCE PRACTICAL FILE ON PYTHON PROGRAMS & MYSQL Submitted by: Submitted to: Rishabh Rawat Mr. Manish Bhatt Roll No.-
  • 2. INDEX Q1. WAP to input a year and check whether the year is leap year or not. Q2. WAP to input 3 numbers and print the greatest number using nested if. Q3. WAP to input value of x and n and print the series along with its sum. Q4. WAP to input a number and check whether it is prime number or not. Q5. WAP to print fibonacci series upto n terms, also find sum of series. Q6. WAP to print the given patterns. Q7. WAP to print a string and the number of vowels present in it. Q8. Write a program to read a file story.txt and print the contents of file along with number of vowels present in it. Q9. Write a program to read a file book.txt print the contents of file along with numbers of words and frequency of word computer in it. Q10. Write a program to read a file Top.txt and print the contents of file along with the number of lines starting with A. Q11. WAP to input a list of number and search for a given number using linear search. Q12. WAP to input a list of integers and search for a given number using binary search. Q13. Write a function DigitSum() that takes a number and returns its digit sum. Q14. Write a function Div3and5() that takes a 10 elements numeric tuple and return the sum of elements which are divisible by 3 and 5. Q15. Write a recursive function ChkPrime() that checks a number for Prime. Q16. Write a function to input a list and arrange the list in ascending order using Bubble sort. Q17. Write a menu based program to demonstrate operation on a stack. Q18. Write a menu based program to demonstrate operations on queue. Q19. MySQL Queries
  • 3. Q20. Python –MYSQL Connectivity 1. # WAP toinput a year and check whether the year is leapyear or not y=int(input("Enter the year: ")) if y%400==0: print("Theyear is a Century Leap Year") elif y%100!=0 and y%4==0: print("Year is a Leap year") else: print("Year is not a leap year") Enter the year:2000 The year is a Century LeapYear 2. #WAP to input 3 numbers and print the greatest number using nestedif a=float(input("Enter the firstnumber: ")) b=float(input("Enter the second number: ")) c=float(input("Enter the third number: ")) if a>=b: if a>=b: print("Firstnumber :",a,"is greatest") if b>a: if b>c: print("Second number :",b,"is greatest") if c>a: if c>b: print("Third number :",c,"is greatest") Enter the first number4
  • 4. Enter the secondnumber2 Enter the thirdnumber2.1 First number : 4.0 is greatest 3.# WAP to input value of x and n and print the series along with its sum x=float(input("Enter the value of x")) n=float(input("Enter the value of n")) i=1 s=0 while i<n: y=x**i print(y, "+", end='') s=s+y i+=1 print(x**n) #to print the last element of series s=s+(x**n) #to add the last element of series print("Sum of series =", s) Enter the value of x4 Enter the value of n2 4.0 +16.0 Sum of series = 20.0 4.# WAP to input a number and check whether it is prime number or not n=int(input("Enter the number")) c=1 for i in range(2,n): if n%i==0: c=0 if c==1: print("Number is prime") else:
  • 5. print("Number is not prime") Enter the number29 Number is prime 5.#WAP to print fibonacci series uptonterms, alsofind sum of series n=int(input("Enter the number of terms in fibonacci series")) a,b=0,1 s=a+b print(a,b,end=" ") for i in range(n-2): print(a+b,end=" ") a,b=b,a+b s=s+b print() print("Sum of",n,"terms of series =",s) Enter the number of terms infibonacci series10 0 1 1 2 3 5 8 13 21 34 Sum of 10 terms of series =88 6. # WAP to print the patterns #1 program to print pattern for i in range(1,6): for j in range(1,i+1): print(j,end="") print() 1 12 123
  • 6. 1234 12345 #2 program to print pattern for i in range(5,0,-1): for j in range(i): print('*',end="") print() ***** **** *** ** * 7.#WAP to print a string and the number of vowels present init st=input("Enter the string") print("Entered string =",st) st=st.lower() c=0 v=['a','e','i','o','u'] for i in st: if i in v: c+=1 print("Number of vowels in entered string =",c) Enter the stringI am a good boi Enteredstring =I am a good boi Number of vowels inenteredstring =7
  • 7. 8.#Write aprogram to reada file story.txt andprint the contents of file along with number of vowels present init f=open("story.txt",'r') st=f.read() print("Contents of file :") print(st) c=0 v=['a','e','i','o','u'] for i in st: if i.lower() in v: c=c+1 print("*****FILEEND*****") print() print("Number of vowels in the file =",c) f.close() Contents of file : Python is an interpreted, high-level, general-purpose programming language. Createdby Guido van Rossumand first releasedin1991. Python's designphilosophy emphasizes code readability. Its language constructs andobject-oriented approachaim to helpprogrammers write clear, logical code. *****FILE END***** Number of vowels inthe file = 114
  • 8. 9.#Write a program to read a file book.txt print the contents of file along with numbers of words and frequency of word computerin it f=open("book.txt","r") L=f.readlines() c=c1=0 v=['a','e','i','o','u'] print("Contents of file :") for i in L: print(i) j=i.split() for k in j: if k.lower()=="computer": c1=c1+1 for x in k: if x .lower() in v: c+=1 print("*****FILE END*****") print() print("Number of vowels in the file =",c) print("Number of times 'computer' in the file =",c1) f.close() Contents of file : Python is an interpreted, high-level, general-purpose computerprogramming language. Created by Guido van Rossum and first released in 1991. Python's design philosophy emphasizes code readability. Its language constructs and object-oriented approach aim to help programmers write clear, logical code. *****FILE END*****
  • 9. Numberof vowels in the file = 92 Numberof times 'computer' in the file = 1 10. #Write a program to read a file Top.txt and print the contents of file along with the number of lines starting with A f=open("Top.txt","r") st=f.readlines() c=0 print("Contents of file:") for i in st: print(i) if i[0]=="A": c+=1 print("n*****FILE END*****") print() print("Number of lines starting with'A' =",c) Contents of file : Python is an interpreted, high-level, general-purposeprogramming language. Created by Guido van Rossum and first released in 1991. Python's design philosophy emphasizes code readability. Its language constructs and object-oriented approach aim to help programmers write clear, logical code. *****FILE END***** Number of lines starting with 'A' = 0 11.#WAP to input a list of number and search for a given number using linear search l=eval(input("Enter thelist of numbers")) x=int(input("Enter thenumber"))
  • 10. for i in l: if i==x: print("ELement present") break else: print("Element not found") Enter the list of numbers[5,3,4,2,1] Enter the number3 ELement present 12.#WAP to input a list of integers and search for a given number using binary search def bsearch(L,n): start=0 end=len(L)-1 whilestart<=end: mid=(start+end)//2 if L[mid]==n: return True elif L[mid]<=n: start=mid+1 else: end=mid-1 else: return False L=eval(input("Enter thelist of numbers")) n=int(input("Enter thenumber to find")) L.sort() if bsearch(L,n): print("Element found") else: print("Element not found")
  • 11. Enter the list of numbers[5,3,4,2,1] Enter the number to find6 ELement not found 13.#Write afunctionDigitSum() that takes a number and returns its digit sum def DigitSum(n): s=0 n=str(n) for i in n: s=s+int(i) return s n=int(input("Enter the number")) print("Sum of digits =",DigitSum(n)) Enter the number69 Sum of digits = 15 14.#Write afunctionDiv3and5() that takes a 10 elements numeric tuple andreturnthe sum of elements whichare divisible by 3 and 5 def Div3and5(t): s=0 for i in t: if i%3==0 and i%5==0: s=s+i return s #main l=[] for i in range(10):
  • 12. print("Enter the ",i+1,"th number of the tuple",end=" ",sep="") e=int(input()) l.append(e) t=tuple(l) print("Entered tuple :",t) print("Sum of numbers in tuple divisible by 3 and 5 =",Div3and5(t)) Enter the 1th number of the tuple 3 Enter the 2th number of the tuple 2 Enter the 3th number of the tuple 5 Enter the 4th number of the tuple 10 Enter the 5th number of the tuple 15 Enter the 6th number of the tuple 20 Enter the 7th number of the tuple 30 Enter the 8th number of the tuple 2 Enter the 9th number of the tuple 67 Enter the 10th number of the tuple 50 Entered tuple : (3, 2, 5, 10, 15, 20, 30, 2, 67, 50) Sum of numbers in tuple divisible by 3 and 5 = 45 15.#Write a recursive function ChkPrime() that checks a number for Prime def ChkPrime(n,i): whilei<n: if n%i==0: return False else: i+=1 ChkPrime(n,i) return True n=int(input("Enter thenumber")) if ChkPrime(n,2):
  • 13. print("Number is prime") else: print("Number ain't prime") Enter the number23 Number is prime 16.#Write afunctiontoinput a list and arrange the list in ascending order using Bubble sort l=eval(input("Enter the list to arrange")) for i in range(len(l)-1): for j in range(len(l)-1): if l[j]>l[j+1]: l[j],l[j+1]=l[j+1],l[j] print("Arranged list:",l) Enter the list toarrange[5,4,2,3,0,1] Arrangedlist :[0, 1, 2, 3, 4, 5] 17.#Write amenu basedprogram to demonstrate operationona stack def isEmpty(stk): if len(stk)==0: return True else: return False def push(stk,n): stk.append(n) def pop(stk): if isEmpty(stk): print("UNDERFLOW CONDITION") else:
  • 14. print("Deleted element:",stk.pop()) def peek(stk): return stk[-1] def display(stk): if isEmpty(stk): print("No Element Present") else: for i in range(-1,-len(stk)-1,-1): if i==-1: print("TOP",stk[i]) else: print(" ",stk[i]) #main stk=[] while True: print(" Stack operations") print(" 1.PUSH") print(" 2.POP") print(" 3.PEEK") print(" 4.DISPLAYSTACK") print(" 5.EXIT") ch=int(input(" Enter the choice")) if ch==1: n=input("Enter the element to PUSH") push(stk,n) print("Element pushed") elif ch==2: pop(stk) elif ch==3: if isEmpty(stk): print("UNDERFLOW CONDITION")
  • 15. else: print(peek(stk)) elif ch==4: display(stk) elif ch==5: break else: print("INVALIDCHOICEENTERED") print("THANKS FOR USING MYSERVICES") Stack operations 1.PUSH 2.POP 3.PEEK 4.DISPLAY STACK 5.EXIT Enter the choice1 Enter the element toPUSH98 Element pushed Stack operations 1.PUSH 2.POP 3.PEEK 4.DISPLAY STACK 5.EXIT Enter the choice1 Enter the element toPUSH76 Element pushed Stack operations 1.PUSH 2.POP
  • 16. 3.PEEK 4.DISPLAY STACK 5.EXIT Enter the choice1 Enter the element to PUSH89 Element pushed Stack operations 1.PUSH 2.POP 3.PEEK 4.DISPLAY STACK 5.EXIT Enter the choice4 TOP 89 76 98 Stack operations 1.PUSH 2.POP 3.PEEK 4.DISPLAY STACK 5.EXIT Enter the choice2 Deletedelement:89 Stack operations 1.PUSH 2.POP 3.PEEK 4.DISPLAY STACK 5.EXIT Enter the choice4
  • 17. TOP 76 98 18.#Write a menu basedprogram to demonstrate operationsonqueue def isEmpty(qu): if len(qu)==0: return True else: return False def ENQUEUE(qu,item): qu.append(item) if len(qu)==1: rear=front=0 else: rear=len(qu)-1 front=0 def DEQUEUE(qu): if isEmpty(qu): print("UNDERFLOW CONDITION") else: a= qu.pop(0) print("ELEMENTDELETED:",a) def peek(stk): return stk[-1] def display(qu): if isEmpty(qu):
  • 18. print("NO ELEMENT PRESENT") else: for i in range(len(qu)): if i==0: print("FRONT",qu[i]) elif i==len(qu)-1: print("REAR",qu[i]) else: print(" ",qu[i]) #main qu=[] while True: print(“tt QUEUE OPERATIONS") print("tt1.ENQUEUE") print("tt2.DEQUEUE") print("tt3.DISPLAYQUEUE") print("tt4.PEEK") print(“tt5.EXIT") ch=int(input("ttEnter your choice: ")) if ch==1: x=input("Enter the element to be inserted: ") ENQUEUE(qu,x) print("ELEMENTHAS BEEN INSERTED") elif ch==2: DEQUEUE(qu) elif ch==3: display(qu) elif ch==4: if isEmpty(qu): print("UNDERFLOW CONDITION") else:
  • 19. print(peek(qu)) elif ch==5: break else: print("INVALIDCHOICEENTERED") print("THANKS FORUSING MYSERVICES") QUEUE OPERATIONS 1.ENQUEUE 2.DEQUEUE 3.DISPLAY QUEUE 4.PEEK 5.EXIT Enter your choice 1 Enter the element tobe inserted:Rishabh ELEMENTHAS BEEN INSERTED QUEUE OPERATIONS 1.ENQUEUE 2.DEQUEUE 3.DISPLAY QUEUE 4.PEEK 5.EXIT Enter your choice 1 Enter the element tobe inserted:Python ELEMENTHAS BEEN INSERTED QUEUE OPERATIONS 1.ENQUEUE 2.DEQUEUE 3.DISPLAY QUEUE 4.PEEK 5.EXIT Enter your choice 1
  • 20. Enter the element tobe inserted:Selenium ELEMENTHAS BEEN INSERTED QUEUE OPERATIONS 1.ENQUEUE 2.DEQUEUE 3.DISPLAY QUEUE 4.PEEK 5.EXIT Enter your choice 3 FRONTRishabh Python REAR Selenium QUEUE OPERATIONS 1.ENQUEUE 2.DEQUEUE 3.DISPLAY QUEUE 4.PEEK 5.EXIT Enter your choice 2 ELEMENTDELETED: Rishabh QUEUE OPERATIONS 1.ENQUEUE 2.DEQUEUE 3.DISPLAY QUEUE 4.PEEK 5.EXIT Enter your choice 3 FRONTPython REAR Selenium QUEUE OPERATIONS 1.ENQUEUE
  • 21. 2.DEQUEUE 3.DISPLAY QUEUE 4.PEEK 5.EXIT Enter your choice 5 THANKS FOR USING MY SERVICES 20#Python –MYSQL Connectivity import mysql.connector def insert(): cur.execute("desc {}".format(table_name)) data=cur.fetchall() full_input="" for i in data: print("NOTE: Pleaseenter string/varchar/datevalues (if any) in quotes") print("Enter the",i[0],end=" ") single_value=input() full_input=full_input+single_value+"," full_input=full_input.rstrip(",") cur.execute("Insertinto {} values({})".format(table_name,full_input)) mycon.commit() print("Record successfully inserted") def display(): n=int(input("Enter the number of records to display ")) cur.execute("Select * from{}".format(table_name)) for i in cur.fetchmany(n): print(i) def search():
  • 22. find=input("Enter the column name using which you wantto find the record ") print("Enter the",find,"of thatrecord",end=" ") find_value=input() cur.execute("select* from{} where {}='{}'".format(table_name,find,find_value)) print(cur.fetchall()) def modify(): mod=input("Enter the field name to modify ") find=input("Enter the column name using which you wantto find the record ") print("Enter the",find,"of thatrecord",end=" ") find_value=input() print("Enter the new",mod,end=" ") mod_value=input() cur.execute("update{} set {}='{}' where {}='{}'".format(table_name,mod,mod_value,find,find_value)) mycon.commit() print("Record sucessfully modified") def delete(): find=input("Enter the column name using which you wantto find the recordnNOTE: NO TWO RECORDS SHOULD HAVESAME VALUEFORTHIS COLUMN: ") print("Enter the",find,"of thatrecord",end=" ") find_value=input() cur.execute("delete from {} where{}='{}'".format(table_name,find,find_value)) mycon.commit() print("Record successfully deleted") #__main__ database_name=input("Enter the database") my_sql_password=input("Enter thepassword for MySQL ")
  • 23. table_name=input("Enter the table name ") mycon=mysql.connector.connect(host="localhost",user="root",database=database_name,p asswd=my_sql_password) cur=mycon.cursor() if mycon.is_connected(): print("Successfully Connected to Database") else: print("Connection Faliled") while True: print("tt1. InsertRecord") print("tt2. Display Record") print("tt3. Search Record") print("tt4. Modify Record") print("tt5. Delete Recod") print("tt6. Exitn") ch=int(input("Enter the choice ")) if ch==1: insert() elif ch==2: display() elif ch==3: search() elif ch==4: modify() elif ch==5: delete() elif ch==6: mycon.close() break else: print("Invalid choiceentered")
  • 24. Enter the database Rishabh Enter the passwordfor MySQL CHUTIYA#1 Enter the table name EMP Successfully ConnectedtoDatabase 1. Insert Record 2. Display Record 3. SearchRecord 4. Modify Record 5. Delete Recod 6. Exit Enter the choice 1 NOTE: Please enter string/varchar/date values (if any) inquotes Enter the EMPNO 120 NOTE: Please enter string/varchar/date values (if any) inquotes Enter the EMPNAME"RishabhRawat" NOTE: Please enter string/varchar/date values (if any) inquotes Enter the DEPT "Computer" NOTE: Please enter string/varchar/date values (if any) inquotes Enter the DESIGN "Coder" NOTE: Please enter string/varchar/date values (if any) inquotes Enter the basic 100000 NOTE: Please enter string/varchar/date values (if any) inquotes Enter the CITY "Srinagar" Recordsuccessfully inserted 1. Insert Record 2. Display Record 3. SearchRecord 4. Modify Record 5. Delete Recod
  • 25. 6. Exit Enter the choice 2 Enter the number of records todisplay 10 (111, 'AkashNarang', 'Account', 'Manager', 50000, 'Dehradun') (112, 'Vijay Duneja', 'Sales', 'Clerk', 21000, 'lucknow') (113, 'Kunal Bose', 'Computer', 'Programmer', 45000, 'Delhi') (114, 'Ajay Rathor', 'Account', 'Clerk', 26000, 'Noida') (115, 'Kiran Kukreja', 'Computer', 'Operator', 30000, 'Dehradun') (116, 'PiyushSony', 'Sales', 'Manager', 55000, 'Noida') (117, 'MakrandGupta', 'Account', 'Clerk', 16000, 'Delhi') (118, 'HarishMakhija', 'Computer', 'Programmer', 34000, 'Noida') (120, 'RishabhRawat', 'Computer', 'Coder', 100000, 'Srinagar') 1. Insert Record 2. Display Record 3. SearchRecord 4. Modify Record 5. Delete Recod 6. Exit Enter the choice 3 Enter the column name using which you want tofind the recordEMPNO Enter the EMPNO of that record120 [(120, 'RishabhRawat', 'Computer', 'Coder', 100000, 'Srinagar')] 1. Insert Record 2. Display Record 3. Search Record 4. Modify Record 5. Delete Recod 6. Exit
  • 26. Enter the choice 4 Enter the fieldname to modify basic Enter the column name using which you want tofind the recordEMPNAME Enter the EMPNAMEof that recordRishabhRawat Enter the new basic 200000 Recordsucessfully modified 1. Insert Record 2. Display Record 3. SearchRecord 4. Modify Record 5. Delete Recod 6. Exit Enter the choice 5 Enter the column name using which you want tofind the record NOTE: NO TWO RECORDS SHOULD HAVESAME VALUE FOR THIS COLUMN:EMPNO Enter the EMPNO of that record120 Recordsuccessfully deleted
  • 27. 19. MySQL Queries 1. SELECT * FROM job; 2. SELECT jobtitle,salary FROM job;
  • 28. 3. SELECT * FROM job WHEREsalary>100000; 4. SELECT MAX(salary) FROM job; 5. SELECT COUNT(DISTINCTjobtitle) FROMjob;
  • 29. 6. SELECT * FROM job WHEREjobtitle LIKE“R%” 7. SELECT * FROM job ORDER BY salary ASC; 8. SELECT SUM(salary) AS “TOTAL SALARY”FROM job;
  • 30. 9. SELECT * FROM CLUB; 10. SELECT * FROM CLUB GROUP BY SPORTS; 11. SELECT * FROM EMP; 12. SELECT CITY,COUNT(*) FROM EMP GROUP BY CITY HAVING COUNT(*)>1;
  • 31. 13. SELECT DEPT,SUM(basic) AS “TOTAL SALARY”FROM EMP GROUP BY DEPT; 14. SELECT * FROM GROUP BY CITY HAVING basic>30000; 15. SELECT * FROM WHERECITY=”Noida” ORDER BY basic ASC;