SlideShare a Scribd company logo
1 of 31
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;

More Related Content

What's hot

Computer science project.pdf
Computer science project.pdfComputer science project.pdf
Computer science project.pdfHarshitSachdeva17
 
Library Management Project (computer science) class 12
Library Management Project (computer science) class 12Library Management Project (computer science) class 12
Library Management Project (computer science) class 12RithuJ
 
Computer Science Practical File class XII
Computer Science Practical File class XIIComputer Science Practical File class XII
Computer Science Practical File class XIIYugenJarwal
 
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12THBANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12THSHAJUS5
 
Physics Practical File - with Readings | Class 12 CBSE
Physics Practical File - with Readings | Class 12 CBSEPhysics Practical File - with Readings | Class 12 CBSE
Physics Practical File - with Readings | Class 12 CBSESaksham Mittal
 
IP Project for Class 12th CBSE
IP Project for Class 12th CBSEIP Project for Class 12th CBSE
IP Project for Class 12th CBSESylvester Correya
 
Physics Investigatory Project Class 12
Physics Investigatory Project Class 12Physics Investigatory Project Class 12
Physics Investigatory Project Class 12Self-employed
 
Computer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market BillingComputer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market BillingHarsh Kumar
 
IP Final project 12th
IP Final project 12thIP Final project 12th
IP Final project 12thSantySS
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfKiranKumari204016
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILEAnushka Rai
 
12th CBSE Computer Science Project
12th CBSE Computer Science Project12th CBSE Computer Science Project
12th CBSE Computer Science ProjectAshwin Francis
 
To Study the earth's magnetic field using a tangent galvanometer Tangent galv...
To Study the earth's magnetic field using a tangent galvanometer Tangent galv...To Study the earth's magnetic field using a tangent galvanometer Tangent galv...
To Study the earth's magnetic field using a tangent galvanometer Tangent galv...Arjun Kumar Sah
 
Chemistry Investigatory Project Class XII
Chemistry Investigatory Project Class XII Chemistry Investigatory Project Class XII
Chemistry Investigatory Project Class XII AsanalMahathir
 
“To estimate the charge induced on each one of the two identical Styrofoam (o...
“To estimate the charge induced on each one of the two identical Styrofoam (o...“To estimate the charge induced on each one of the two identical Styrofoam (o...
“To estimate the charge induced on each one of the two identical Styrofoam (o...VanshPatil7
 
Project front page, index, certificate, and acknowledgement
Project front page, index, certificate, and acknowledgementProject front page, index, certificate, and acknowledgement
Project front page, index, certificate, and acknowledgementAnupam Narang
 
Physics activity file class 12
Physics activity file class 12Physics activity file class 12
Physics activity file class 12Titiksha Sharma
 

What's hot (20)

Computer science project.pdf
Computer science project.pdfComputer science project.pdf
Computer science project.pdf
 
Library Management Project (computer science) class 12
Library Management Project (computer science) class 12Library Management Project (computer science) class 12
Library Management Project (computer science) class 12
 
Computer Science Practical File class XII
Computer Science Practical File class XIIComputer Science Practical File class XII
Computer Science Practical File class XII
 
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12THBANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
 
Physics Practical File - with Readings | Class 12 CBSE
Physics Practical File - with Readings | Class 12 CBSEPhysics Practical File - with Readings | Class 12 CBSE
Physics Practical File - with Readings | Class 12 CBSE
 
IP Project for Class 12th CBSE
IP Project for Class 12th CBSEIP Project for Class 12th CBSE
IP Project for Class 12th CBSE
 
ASL/ALS CLASS 12 ENGLISH PROJECT
ASL/ALS CLASS 12 ENGLISH PROJECTASL/ALS CLASS 12 ENGLISH PROJECT
ASL/ALS CLASS 12 ENGLISH PROJECT
 
Physics Investigatory Project Class 12
Physics Investigatory Project Class 12Physics Investigatory Project Class 12
Physics Investigatory Project Class 12
 
Computer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market BillingComputer science class 12 project on Super Market Billing
Computer science class 12 project on Super Market Billing
 
IP Final project 12th
IP Final project 12thIP Final project 12th
IP Final project 12th
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
 
12th CBSE Computer Science Project
12th CBSE Computer Science Project12th CBSE Computer Science Project
12th CBSE Computer Science Project
 
To Study the earth's magnetic field using a tangent galvanometer Tangent galv...
To Study the earth's magnetic field using a tangent galvanometer Tangent galv...To Study the earth's magnetic field using a tangent galvanometer Tangent galv...
To Study the earth's magnetic field using a tangent galvanometer Tangent galv...
 
Chemistry Investigatory Project Class XII
Chemistry Investigatory Project Class XII Chemistry Investigatory Project Class XII
Chemistry Investigatory Project Class XII
 
English Project work.pdf
English Project work.pdfEnglish Project work.pdf
English Project work.pdf
 
“To estimate the charge induced on each one of the two identical Styrofoam (o...
“To estimate the charge induced on each one of the two identical Styrofoam (o...“To estimate the charge induced on each one of the two identical Styrofoam (o...
“To estimate the charge induced on each one of the two identical Styrofoam (o...
 
Project front page, index, certificate, and acknowledgement
Project front page, index, certificate, and acknowledgementProject front page, index, certificate, and acknowledgement
Project front page, index, certificate, and acknowledgement
 
Physics activity file class 12
Physics activity file class 12Physics activity file class 12
Physics activity file class 12
 
Transformer(Class 12 Investigatory Project)
Transformer(Class 12 Investigatory Project)Transformer(Class 12 Investigatory Project)
Transformer(Class 12 Investigatory Project)
 

Similar to CBSE Class 12 Computer practical Python Programs and MYSQL

Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsProf. Dr. K. Adisesha
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdfYashMirge2
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysisVishal Singh
 
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONPART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONAndrea Antonello
 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxjeyel85227
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxadihartanto7
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfrajatxyz
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using cArghodeepPaul
 
week4_python.docx
week4_python.docxweek4_python.docx
week4_python.docxRadhe Syam
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...DR B.Surendiran .
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdfCBJWorld
 

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

Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programs
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdf
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
PART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHONPART 3: THE SCRIPTING COMPOSER AND PYTHON
PART 3: THE SCRIPTING COMPOSER AND PYTHON
 
paython practical
paython practical paython practical
paython practical
 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
 
gdscpython.pdf
gdscpython.pdfgdscpython.pdf
gdscpython.pdf
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 
week4_python.docx
week4_python.docxweek4_python.docx
week4_python.docx
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
 
PYTHON PROGRAMS
PYTHON PROGRAMSPYTHON PROGRAMS
PYTHON PROGRAMS
 
R basic programs
R basic programsR basic programs
R basic programs
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 

Recently uploaded

Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 

Recently uploaded (20)

Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 

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;