0% found this document useful (0 votes)
41 views12 pages

Practical Programs For The Practical Exam

Hi

Uploaded by

suryamahesh2401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views12 pages

Practical Programs For The Practical Exam

Hi

Uploaded by

suryamahesh2401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

PYTHON

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)

Text File Content


Like a Joy on the heart of a sorrow.
The sunset hangs on a cloud.

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()

def Search ():


F=open("Students.dat", 'rb')
no=int(input("Enter Roll. No of student to search:"))
found=0
try:
while True:
S=pickle.load (F)
if S[0]==no:
print("The searched Roll. No is found and Details are:",S)
found=1
break
except:
F.close()

if found==0:
print("The Searched Roll. No is not found")

#Main Program
Create ()
Search ()
found=1

Output 1 - Record found


Enter roll number:1
Enter Name:Arun
Do you want to add another student detail(y/n):y
Enter roll number:2
Enter Name:Bala
Do you want to add another student detail(y/n):y
Enter roll number:3
Enter Name:Charan
Do you want to add another student detail(y/n):y
Enter roll number:4
Enter Name:Dinesh
Do you want to add another student detail(y/n):y
Enter roll number:5
Enter Name:Dharani
Do you want to add another student detail(y/n):n
Enter Roll. No of student to search:3
The searched Roll. No is found and Details are: [3, 'Charan']

Output 2 - Record not found


Enter roll number:6
Enter Name:Michael
Do you want to add another student detail(y/n):n
Enter Roll. No of student to search:7
The Searched Roll. No is not found
EX.NO: 14 - CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(LIST)

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

Performing Stack Operations Using List

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

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:1
Enter the Doctor ID:2
Enter the Name of the Doctor:Raghu
Enter the Mobile Number of the Doctor:88888349
Enter the Specialization:Cardio

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:1
Enter the Doctor ID:3
Enter the Name of the Doctor:Rajesh
Enter the Mobile Number of the Doctor:88888343
Enter the Specialization:ENT

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:4
[3, 'Rajesh']
[1, 'Ravi']

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:3
The top of the stack is: [3, 'Rajesh']

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:2
The deleted doctor detail is: [3, 'Rajesh']

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:4
[1, 'Ravi']

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:2
The deleted doctor detail is: [1, 'Ravi']

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:4
Stack is empty

Do you want to Perform another operation(y/n):y


1.PUSH
2.POP
3.PEEK
4.Disp
Enter your choice:2
Stack is empty

Do you want to Perform another operation(y/n):n


EX.NO: 18 - CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON(SEARCHING AND
DISPLAYING RECORDS)

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

ItemNo Item DCode Qty UnitPrice StockDate


5005 Ball Pen 0.5 102 100 16 31-Mar-10
5003 Ball pen 0.25 102 150 20 01-Jan-10
5002 Gel pen Premium 101 125 14 14-Feb-10
5006 Gel pen classic 101 200 22 01-Jan-09
5001 Eraser Small 102 210 5 19-Mar-09
5004 Eraser Big 102 60 10 12-Dec-09
5009 Sharpener 103 160 8 23-Jan-09
Classic

a. Write SQL commands for the following statements:

(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

ECODE NAME DESIG SGRADE DOJ DOB


101 Abdul Ahmad Executive S03 23-Mar-2003 13-Jan-1980
102 Ravi Chander Head-IT S02 12-Feb-2010 22-Jul-1987
103 John Ken Receptionist S03 24-Jun-2009 24-Feb-1983
105 Nazar Ameen GM S02 11-Aug-2006 03-Mar-1984
108 Priyam Sen CEO S01 29-Dec-2004 19-Jan-1982

Write SQL commands for the following statements:

(i) To display the details of all Employees in descending order of DOJ.


Ans. select * from employee order by doj desc;

(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';

(iv) To display different grades, present in the table employee.


Ans. select distinct sgrade from employee;

You might also like