0% found this document useful (0 votes)
9 views

CS_practical_programs-1

The document provides a series of Python programming exercises and SQL queries for practical exam preparation. It includes tasks such as reading and processing text files, creating CSV files, implementing stack operations, and performing database operations on tables like HOSTEL, PATIENT, CANDIDATE, and ACTIVITY. Each exercise is accompanied by step-by-step instructions and code snippets for implementation.

Uploaded by

koushikjee123
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)
9 views

CS_practical_programs-1

The document provides a series of Python programming exercises and SQL queries for practical exam preparation. It includes tasks such as reading and processing text files, creating CSV files, implementing stack operations, and performing database operations on tables like HOSTEL, PATIENT, CANDIDATE, and ACTIVITY. Each exercise is accompanied by step-by-step instructions and code snippets for implementation.

Uploaded by

koushikjee123
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/ 7

NATHELLA VIDYODAYA

QUESTIONS FOR PRACTICAL EXAM PREPARATION


1) Write a python program to read a text file line by line and display each word separated
by #.
Step 1: Open a notepad file, type some content in the notepad file and save the file in the name
“myfile”.
Step 2: Type the following code in IDLE and execute the program.
fh=open('myfile.txt','r')
all_lines = fh.read()
words = all_lines.split()
for i in words:
print(i,end='#')

2) Write a python program to create a csv file for storing the user id and password and display the
contents of the file
import csv
myfile = open('user.csv','w',newline='')
u_writer= csv.writer(myfile)
u_writer.writerow(['USER ID','PASSWORD'])
ch='y'
while ch=='y':
user_id = input('Enter the User id : ')
password= input('Enter the Password : ')
user_detail=[user_id,password]
u_writer.writerow(user_detail)
ch=input("Do you want to enter more record?(y/n)...")
print('File created successfully')
myfile.close()
with open('user.csv','r', newline='\n') as fh:
u_reader= csv.reader(fh)
for rec in u_reader:
print("Password for the user id",rec[0],'is--->',rec[1])
3) Write a Program that reads a text file line by line and prints its statistics like:
Number of uppercase letters:
Number of lowercase letters:
Number of vowels:
Number of consonants:
fh=open('myfile.txt','r')
line=fh.read()
lcount=ucount=0
vcount=ccount=0
for a in line:
if a.isalpha():
if a.islower():
lcount+=1
else:
ucount+=1
if a in 'aeiouAEIOU':
vcount+=1
else:
ccount+=1
print("THE FILE CONTENT")
print(line)
print('-----------------------------------------------------------')
print("Number of uppercase letters:",ucount)
print("Number of lowercase letters:",lcount)
print("Number of vowels:",vcount)
print("Number of consonants:",ccount)
4) Write a menu based program to implement a stack for these book-details (bookno, book
name). That is, now each item node the stack contains two types of information - a bookno
and its name. Just implement Push, Pop and Display operations.

stack=[]
def display():
if(stack==[]):
print("Stack is empty")
else:
print("Stack contents")
for x in range(len(stack)-1,-1,-1):
print(stack[x])
def push():
bdetails=[]
bno=int(input("Enter Book no: "))
bname=input("Enter the Book Name:")
bdetails=[bno,bname]
stack.append(bdetails)
def pop( ):
if(stack==[]):
print("Stack is empty")
else:
item=stack.pop(-1)
print("Deleted element:",item)
print("Stack operation")
print("************")
print("1.PUSH")
print("2.POP")
print("3.DISPLAY")
print("4.EXIT")
while True:
print("------------------------")
choice=int(input("Enter your choice :"))
if choice==1:
push()
elif choice==2:
pop()
elif choice==3:
display()
elif choice==4:
print("Exiting the program...")
break
else:
print("Wrong choice")

5) Write a python program to copy all the lines that start with the character `T' from a text
file and write it to another text file.

Step 1: Open a notepad file, type some content in the notepad file and save the file in the name
“original”.
Step 2:
fin=open("original.txt","r")
fout=open("copied.txt","w")
l1=fin.readlines()
for line in l1:
if line[0] in 'tT':
fout.write(line)
fin.close()
fout.close()
print("Work completed successfully")
6) Write a python program to write the employee details in the binary file and display the
contents of the binary file.
import pickle
emp={}
empfile=open('emp.dat','wb')
ans='y'
while ans.lower()=='y':
eno=int(input("Enter employee number :"))
ename=input("Enter employee name:")
designation=input("Enter designation:")
emp[eno]=[ename,designation]
ans=input("Do you want to enter more record?(y/n)...")
pickle.dump(emp,empfile)
empfile.close()
empfile=open('emp.dat','rb')
emp=pickle.load(empfile)
for i in emp:
print("The details of the employee ",i," is:")
print("Employee Name ------>",emp[i][0])
print("Designation--------->",emp[i][1])
empfile.close()
MYSQL QUESTIONS
1) Consider the table HOSTEL given below and write the output of the SQL queries that follow.
Table: HOSTEL
H_NO CATEGORY WARDER_NAME CHARGES FACILITY STU_NAME

GH-1 AC Ms. Sangeeta 50000 Food Neha


Kapoor
BH-2 NON-AC Mr. Satinder 40000 Food Vikas Jain
GH-2 NON-AC Ms. Sakshi 42000 Laundry Manisha
Gupta
BH-3 AC Mr. Rohan 52000 Food Amit Jindal

GH-5 AC Ms. Vineeta 50000 Laundry Shreya


Sharm
Based on the given table. Write SQL statement for the following:
(i) To increment the charges of the hostel by 5% for ’AC’ category.
(ii) To add one more column Date_of_Admission to the above table.
(iii)Display the student name, hostel number whose name ends with ‘a’.
(iv) Display the hostel number and warden name which has charges from 40000 to 45000.

2) Consider the table PATIENT given below:


Table: PATIENT
PNAME AGE WARD ADMITDATE TARIFF SEX
KARIM 32 ORTHO 2012-02-19 1600 M
ARUN 12 SURGERY 2012-11-01 1900 M
ZAFAR 30 ENT 2012-01-12 1500 M
KIRAN 16 ENT 2012-02-24 1500 F
ANKUR 29 CARDIO 2012-02-20 1800 F
SUHAIL 45 ORTHO 2012-02-22 1600 F
KETAN 19 CARDIO 2012-01-13 1800 M
ANUSHA 23 SURGERY 2012-02-21 1900 F
ARPIT 42 CARDIO 2012-02-23 1800 M
TARUN 53 SURGERY 2012-01-17 1900 M
GAURAV 39 ENT 2012-10-11 1500 F
Based on the given table. Write SQL statement for the following:
(i) List the complete information of all male patients in SURGERY ward.
(ii) Increase the TARIFF of ORTHO ward by 15%.
(iii)Display a report showing PNAME, AGE, WARD and (7*TARIFF)
(iv) Count the number of patients in each ward.
3) Consider the table Candidate given below:
Table: CANDIDATE

Candidate_No C_Name Department Stipend Gender


101 Manoj Finance 32000 M
303 Vinay HR 42500 M

401 Mansi Finance 31500 F


603 Kamal IT 32150 M
604 Veena HR 42000 F
631 Sujata Finance 39500 F

Based on the given table. Write SQL statement for the following:
(i) To create the above table using primary key constraint.
(ii) Delete records of female candidates
(iii) Display all the records of candidate whose stipend is more than 44000.

(iv) Increase the stipend of all the candidates by 10%

4) Consider the table Candidate given below:


Table: ACTIVITY
ACODE ACTIVITY PARTICIPANTS PRIZE SCHEDULED
NAME MONEY
1001 Relay 16 10000 2004-01-23
1002 High Jump 10 12000 2003-12-12

1003 Shot Put 12 8000 2004–2-14


1005 Ling Jump 12 9000 2004-02-01
1008 Discuss Throw 10 15000 2004–01-01

Based on the given table. Write SQL statement for the following:
(i) To create the above table using primary key constraint.
(ii) Display the details of all activities in which prize money is more than 9000 (including 9000)
(iii) Increase the prize money by 5% of those activities whose schedule date is after 1st of March
2023.
(iv) Delete the record of activity where participants are less than 12.

You might also like