Practical Programs For The Practical Exam
Practical Programs For The Practical Exam
1. EX.NO: 8 - CREATING A PYTHON PROGRAM TO READ A TEXT FILE AND DISPLAY THE NUMBER OF
VOWELS/CONSONANTS/LOWER CASE/ UPPER CASE CHARACTERS.
AIM :
To write a python program to read a text file and display the number of vowels/consonants/lower case/
upper case characters.
Program :
f=open("Story.txt",'r')
Contents=f.read()
Vowels=0
Consonants=0
Lower_case=0
Upper_case=0
for ch in Contents:
if ch in 'aeiouAEIOU':
Vowels=Vowels+1
if ch in 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ':
Consonants=Consonants+1
if ch.islower ():
Lower_case=Lower_case+1
if ch.isupper ():
Upper_case=Upper_case+1
f.close()
print("The total numbers of vowels in the file:",Vowels)
print("The total numbers of consonants in the file:", Consonants)
print("The total numbers of uppercase in the file:", Upper_case)
print("The total numbers of lowercase in the file:", Lower_case)
Output
The total numbers of vowels in the file: 20
The total numbers of consonants in the file: 29
The total numbers of uppercase in the file: 3
The total numbers of lowercase in the file: 46
2. EX.NO: 11 - CREATING A PYTHON PROGRAM TO CREATE AND SEARCH RECORDS IN BINARY FILE
AIM :
To write a python program to create and search records in binary file.
Program :
import pickle
def Create ():
F=open("Students.dat", 'ab')
opt='y'
while opt=='y':
Roll_No=int(input('Enter roll number:'))
Name=input("Enter Name:")
L=[Roll_No, Name]
pickle.dump (L,F)
opt=input("Do you want to add another student detail(y/n):")
F.close()
if found==0:
print("The Searched Roll. No is not found")
#Main Program
Create ()
Search ()
found=1
AIM :
To write a python program to implement stack operations(list)
Program :
def Push():
Doc_ID=int(input("Enter the Doctor ID:"))
Doc_Name=input("Enter the Name of the Doctor:")
Mob=int(input("Enter the Mobile Number of the Doctor:"))
Special=input("Enter the Specialization:")
if Special=='ENT':
Stack.append([Doc_ID,Doc_Name])
def Pop():
if Stack==[ ]:
print("Stack is empty")
else:
print("The deleted doctor detail is:", Stack.pop())
def Peek():
if Stack==[ ]:
print("Stack is empty")
else:
top=len(Stack)-1
print("The top of the stack is:", Stack[top])
def Disp():
if Stack==[ ]:
print("Stack is empty")
else:
top=len(Stack)-1
for i in range(top,-1,-1):
print(Stack[i])
Stack=[]
ch='y'
print("Performing Stack Operations Using List\n")
while ch=='y' or ch=='Y':
print("1.PUSH")
print("2.POP")
print("3.PEEK")
print("4.Disp")
opt=int(input("Enter your choice:"))
if opt==1:
Push()
elif opt==2:
Pop()
elif opt==3:
Peek()
elif opt==4:
Disp()
else:
print("Invalid Choice, Try Again!!!")
ch=input("\nDo you want to Perform another operation(y/n):")
Output
1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:1
Enter the Doctor ID:1
Enter the Name of the Doctor:Ravi
Enter the Mobile Number of the Doctor:88888342
Enter the Specialization:ENT
AIM :
To write a python program to integrate mysql with python (searching and displaying records)
Program :
import mysql.connector
con=mysql.connector.connect (host='localhost', username='root',password='root', database='employees')
if con.is_connected():
cur=con.cursor()
print("*****************************************")
print("Welcome to Employee Search Screen")
print("*****************************************")
No=int(input("Enter the employee number to search: "))
Query="SELECT * FROM EMP WHERE ENO={}".format (No)
cur.execute (Query)
data=cur.fetchone()
if data!=None:
print (data)
else:
print("Record not Found!!!")
con.close()
output:
*****************************************
Welcome to Employee Search Screen
*****************************************
Enter the employee number to search: 5
(5, 'ram', 'M', 48000)
*****************************************
Welcome to Employee Search Screen
*****************************************
Enter the employee number to search: 6
Record not Found!!!
MYSQL
1. Consider the following table STOCK
Table: Stock
(i) To display details of all Items in the stock table in ascending order of stockdate.
Ans. select * from stock order by stockdate;
(ii) To display ItemNo and Item name of those items from stock table whose
UnitPrice is more than 10
Ans. select ItemNo,Item from stock where UnitPrice>10;
(iii) To display the details of those items whose dealer code(Dcode) is 102 or
quantity in stock(Qty) is more than 100 from the table stock
Ans. Select * from stock where dcode=102 or qty>100;
(iv) To display the maximum and minimum quantity of stock whose price is between
10 and 20.
Ans. select max(qty),min(qty) from stock where UnitPrice between 10 and 20;
2. Consider the following table EMPLOYEE
Table: EMPLOYEE
(ii) To display NAME and DESIG of those Employees whose SGRADE is either
s02 or s03
Ans. select name,desig from employee where sgrade='s02' or sgrade='s03';
(iii) To display the content of the entire Employees table, whose DOJ is in
between ’09-Feb-2006’ and ’08-Aug-2009’.
Ans. select * from employee where doj between '2006/02/09' and '2009/08/08';