0% found this document useful (0 votes)
11 views16 pages

Prac-Final Code

The document contains Python programs for reading text files and counting characters, creating and searching student records using pickle, and managing employee data with CSV files. It also includes SQL queries for various operations on student and uniform tables, such as calculating average prices, displaying records, and filtering data based on conditions. Additionally, it features a stack implementation in Python for managing doctor details based on specialization.

Uploaded by

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

Prac-Final Code

The document contains Python programs for reading text files and counting characters, creating and searching student records using pickle, and managing employee data with CSV files. It also includes SQL queries for various operations on student and uniform tables, such as calculating average prices, displaying records, and filtering data based on conditions. Additionally, it features a stack implementation in Python for managing doctor details based on specialization.

Uploaded by

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

SET-A

Write a python program to read a text file and display the number of vowels/consonants
/lower case/ upper case characters.

f=open (r"D:\Users\User\Desktop\anime.txt", 'r')

Contents=f.read()

Vowels=0

Consonants=0

Lower_case=0

Upper_case=0

space=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

if ch.isspace():

space=space+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)

print("The total numbers of Space in the file:", space)

2. Write the MYSQL query for the following tables. (4)


Table : uniform

Ucode Uname Ucolor StockDate

1 Shirt White 31-03-2021

2 Pant Black 01-01-2020

3 Skirt Grey 18-02-2021

4 Tie Blue 01-01-2019

5 Socks Blue 19-03-2019

6 Belt Black 09-12-2017

Table : Cost

Ucode Size Price Company

1 M 500 Raymond

1 L 580 Mattex

2 XL 620 Mattex

2 M 810 Yasin

2 L 940 Raymond

3 M 770 Yasin

3 L 830 Galin

4 S 150 Mattex

(a) Display the average price of all the Uniform of Raymond Company from table COST.
(b) Display details of all the Uniform in the Uniform table in descending order of Stock
date.
(c) Display max price and min price of each company.
(d) Display the company where the number of uniforms size is more than 2.
SET-A

CREATE TABLE Uniform (

Ucode INT PRIMARY KEY,

Uname VARCHAR(50) NOT NULL,

Ucolor VARCHAR(50) NOT NULL,

StockDate DATE NOT NULL

);

CREATE TABLE Cost (

Ucode INT NOT NULL,

Size VARCHAR(10) NOT NULL,

Price DECIMAL(10, 2) NOT NULL,

Company VARCHAR(50) NOT NULL,

FOREIGN KEY (Ucode) REFERENCES Uniform(Ucode)

);

INSERT INTO Uniform (Ucode, Uname, Ucolor, StockDate)

VALUES (1, 'Shirt', 'White', '2021-03-31');

INSERT INTO Uniform (Ucode, Uname, Ucolor, StockDate)


VALUES (2, 'Pant', 'Black', '2020-01-01');

INSERT INTO Uniform (Ucode, Uname, Ucolor, StockDate)

VALUES (3, 'Skirt', 'Grey', '2021-02-18');

INSERT INTO Uniform (Ucode, Uname, Ucolor, StockDate)

VALUES (4, 'Tie', 'Blue', '2019-01-01');

INSERT INTO Uniform (Ucode, Uname, Ucolor, StockDate)

VALUES (5, 'Socks', 'Blue', '2019-03-19');

INSERT INTO Uniform (Ucode, Uname, Ucolor, StockDate)

VALUES (6, 'Belt', 'Black', '2017-12-09');

INSERT INTO Cost (Ucode, Size, Price, Company)

VALUES (1, 'M', 500, 'Raymond');

INSERT INTO Cost (Ucode, Size, Price, Company)

VALUES (1, 'L', 580, 'Mattex');

INSERT INTO Cost (Ucode, Size, Price, Company)

VALUES (2, 'XL', 620, 'Mattex');


INSERT INTO Cost (Ucode, Size, Price, Company)

VALUES (2, 'M', 810, 'Yasin');

INSERT INTO Cost (Ucode, Size, Price, Company)

VALUES (2, 'L', 940, 'Raymond');

INSERT INTO Cost (Ucode, Size, Price, Company)

VALUES (3, 'M', 770, 'Yasin');

INSERT INTO Cost (Ucode, Size, Price, Company)

VALUES (3, 'L', 830, 'Galin');

INSERT INTO Cost (Ucode, Size, Price, Company)

VALUES (4, 'S', 150, 'Mattex');

a)SELECT AVG(Price) AS AveragePrice FROM Cost WHERE Company = 'Raymond';

b)SELECT * FROM Uniform ORDER BY STR_TO_DATE(StockDate, '%d-%m-%Y') DESC;

c) SELECT Company, MAX(Price) AS MaxPrice, MIN(Price) AS MinPrice FROM Cost


GROUP BY Company;

d)SELECT Company FROM Cost GROUP BY Company HAVING COUNT(DISTINCT Size)


> 2;

SET-B

import pickle

def Create():
F=open ("Students.dat", 'ab')

Roll_No=int(input ('Enter roll number:'))

Name=input ("Enter Name:")

Marks= int(input ('Enter Marks:'))

L= [Roll_No, Name, Marks]

pickle.dump (L,F)

print("Students data added successfully")

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
def main():

while True:

print("\n1. Create Student Records")

print("2. Search Record")

print("3. Exit")

choice = input("Enter your choice (1/2/3): ").strip()

if choice == '1':

Create()

elif choice == '2':

Search ()

elif choice == '3':

print("Exiting program. Goodbye!")

break

else:

print("Invalid choice. Please try again.")

main()

2. Write the MYSQL query for the following tables. (4)

Table : Student

Rollno Name Gender Age Dept DOA Fees

1 Arun M 24 COMPUTER 1997-01-10 120

2 Ankit M 21 HISTORY 1998-03-24 200

3 Anu F 20 HINDI 1996-12-12 300

4 Bala M 19 NULL 1999-07-01 400

5 Charan M 18 HINDI 1997-09-05 250


6 Deepa F 19 HISTORY 1997-06-27 300

7 Dinesh M 22 COMPUTER 1997-02-25 210

8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to display the name of the students whose name is ends with 'N'.

(b) Write a Query to display all the names in ascending order .


(c) Write a query to display the Roll number, Name, and Department of students whose age is
18
from the Student table.
(d) To show all information about students of History department.

SET-B

a) SELECT Name FROM STU WHERE Name LIKE '%N';

b) SELECT Name FROM STU ORDER BY Name ASC;

c)SELECT Rollno, Name, Dept

FROM Student

WHERE Age = 18;

d)SELECT * FROM STU WHERE Dept = 'HISTORY';

SET-C

Write a Python program Create a CSV file to store Empno, Name, Salary and search any
Empno and display Name, Salary and if not found display appropriate message.

import csv
def Create():

file_path = r"D:\Users\User\Desktop\carton.txt"

F= open(file_path, "w", newline='')

W = csv.writer(F)

opt = 'y'

while opt.lower() == 'y':

No = int(input("Enter Employee Number: "))

Name = input("Enter Employee Name: ")

Sal = float(input("Enter Employee Salary: "))

L = [No, Name, Sal]

W.writerow(L)

print("Employee details added successfully.")

opt = input("Do you want to continue (y/n)? ").strip()

def Search():

file_path = r"D:\Users\User\Desktop\carton.txt"

F= open(file_path, 'r')

no = input("Enter Employee number to search: ").strip()

found = False

row = csv.reader(F)

for data in row:

if data[0] == no:

print("\n\tEmployee Details are:")

print("\t**********************")
print("\tEMP_No:", data[0])

print("\tName:", data[1])

print("\tSalary:", data[2])

print("\t**********************")

found = True

break

if not found:

print("The searched Employee number is not found.")

Create()

Search()

2. Write the MYSQL query for the following tables. (4)

Table : Student

Rollno Name Gender Age Dept DOA Fees

1 Arun M 24 COMPUTER 1997-01-10 120

2 Ankit M 21 HISTORY 1998-03-24 200

3 Anu F 20 HINDI 1996-12-12 300

4 Bala M 19 NULL 1999-07-01 400

5 Charan M 18 HINDI 1997-09-05 250

6 Deepa F 19 HISTORY 1997-06-27 300

7 Dinesh M 22 COMPUTER 1997-02-25 210

8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to list name of female students in Hindi Department.

(b) Write a Query to list name of the students whose ages are between 18 to 20.
(c) Write a Query to display the name of the students whose name is starting with 'A'.

(d) Write a query to list the names of those students whose name have second alphabet 'n' in
their

names.

SQL

CREATE TABLE Student (

Rollno INT PRIMARY KEY,

Name VARCHAR(50) NOT NULL,

Gender CHAR(1) CHECK (Gender IN ('M', 'F')),

Age INT NOT NULL,

Dept VARCHAR(50),

DOA DATE NOT NULL,

Fees DECIMAL(10, 2) NOT NULL

);

INSERT INTO Student (Rollno, Name, Gender, Age, Dept, DOA, Fees)

VALUES (1, 'Arun', 'M', 24, 'COMPUTER', '1997-01-10', 120.00);

INSERT INTO Student (Rollno, Name, Gender, Age, Dept, DOA, Fees)

VALUES (2, 'Ankit', 'M', 21, 'HISTORY', '1998-03-24', 200.00);

INSERT INTO Student (Rollno, Name, Gender, Age, Dept, DOA, Fees)

VALUES (3, 'Anu', 'F', 20, 'HINDI', '1996-12-12', 300.00);


INSERT INTO Student (Rollno, Name, Gender, Age, Dept, DOA, Fees)

VALUES (4, 'Bala', 'M', 19, NULL, '1999-07-01', 400.00);

INSERT INTO Student (Rollno, Name, Gender, Age, Dept, DOA, Fees)

VALUES (5, 'Charan', 'M', 18, 'HINDI', '1997-09-05', 250.00);

INSERT INTO Student (Rollno, Name, Gender, Age, Dept, DOA, Fees)

VALUES (6, 'Deepa', 'F', 19, 'HISTORY', '1997-06-27', 300.00);

INSERT INTO Student (Rollno, Name, Gender, Age, Dept, DOA, Fees)

VALUES (7, 'Dinesh', 'M', 22, 'COMPUTER', '1997-02-25', 210.00);

INSERT INTO Student (Rollno, Name, Gender, Age, Dept, DOA, Fees)

VALUES (8, 'Usha', 'F', 23, NULL, '1997-07-31', 200.00);

a) SELECT Name FROM Student WHERE Gender = 'F' AND Dept = 'HINDI';

b)SELECT Name FROM Student WHERE Age BETWEEN 18 AND 20;

c) SELECT Name FROM Student WHERE Name LIKE 'A%';

d) SELECT Name FROM Student WHERE Name LIKE '_n%';


SET-D

1. Write a Python program to implement Stack using a list data-structure, to perform the
following operations:

(i) Push an object containing DocID and Doc_name of doctors who specialize in "ENT" to
the stack.
(ii) To Pop the objects from the stack and display them.
(iii) To display the elements of the stack (after performing PUSH or POP)

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

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):")

2. Write the MYSQL query for the following tables. (4)

Table : Student

Rollno Name Gender Age Dept DOA Fees

1 Arun M 24 COMPUTER 1997-01-10 120

2 Ankit M 21 HISTORY 1998-03-24 200

3 Anu F 20 HINDI 1996-12-12 300

4 Bala M 19 NULL 1999-07-01 400

5 Charan M 18 HINDI 1997-09-05 250

6 Deepa F 19 HISTORY 1997-06-27 300

7 Dinesh M 22 COMPUTER 1997-02-25 210

8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to delete the details of Roll number is 8.


(b) Write a Query to change the fess of Student to 170 whose Roll number is 1,
if the existing fess is less than 130.
(c) Write a Query to add a new column Area of type varchar in table STU
(d) Write a Query to delete Area Column from the table STU.

SQL

(a) Write a Query to delete the details of Roll number is 8.


a) DELETE FROM Student WHERE Rollno = 8;

(b) Write a Query to change the fess of Student to 170 whose Roll number is 1,
if the existing fess is less than 130.
b) UPDATE Student SET Fees = 170 WHERE Rollno = 1 AND Fees < 130;

(c) Write a Query to add a new column Area of type varchar in table STU

c) ALTER TABLE STU ADD Area VARCHAR(50)

(d) Write a Query to delete Area Column from the table STU.

d) ALTER TABLE STU DROP COLUMN Area;

You might also like