Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

.Q-1 a) Write a program to read a text file my_file.

txt and display the number of


vowels/consonants/uppercase/lowercase characters in the file.
Aim:
To write a program to read a text file my_file.txt and display the number of
vowels/consonants/uppercase/lowercase characters in the file.
Example:
File Contents as given below
Python is super and trending language.
Allows to store the output in the files.
A text file stores textual data.
Program output must be as follows
Vowels: 35
Consonants: 58
Uppers: 3
Lowers: 87
f=open(r"F:\SKVV 2022-2023\Class Materials\class 12_Lessons\PRACTICAL 2022-
23\SKV 2022-23\my_file.txt")
d=f.read()
v=0
c=0
u=0
l=0
for i in d:
if i.isupper():
u+=1
elif i.islower():
l+=1
if i.lower() in 'aeiou':
v+=1
elif i.isspace():
pass
elif i.lower() not in 'aeiou':
c+=1
print("Vowels:",v)
print("Consonants:",c)
print("Uppers:",u)
print("Lowers:",l)
f.close()
Output:
Vowels: 35
Consonants: 58
Uppers: 3
Lowers: 87
Result:
Thus, the above program was executed successfully.

b)Write SQL queries on the basis of following table.


Empid EmpName Department Salary Gender
101 Mahesh Finance 32000 M
303 Vijay HR 42500 M
401 Mansha Finance 31500 F
603 Kamal Computer 32150 M
604 Vandana HR 42000 F
631 Sujata Finance 39500 F

i. Increase salary of all employees by 1000.


ii. Decrease value of EmpID of male employees by 10.

iii. Department of ‘Mahesh’ should be updated as ‘HR’.

iv)Name should be updated as ‘Manish Saini’ and salary as 50000 for employee id

i. Increase salary of all employees by 1000.

Ans. update emp set salary=salary+1000;

ii. Decrease value of EmpID of male employees by 10.

Ans. update emp set empid=empid-10 where gender=’M’;

iii. Department of ‘Mahesh’ should be updated as ‘HR’.

Ans. update emp set department=’HR’ where empname=’Mahesh’;

iv. Name should be updated as ‘Manish Saini’ and salary as 50000 for employee id

603.

Ans. update emp set empname=’Manish Saini’, salary=50000 where empid=603;

Q-2 a) Write a program to count a total number of lines and count the total number of
lines starting with 'A', 'B', and 'C' from the file myfile.txt.
Example:
File Contents as given below
Python is super and trending language.
Allows to store the output in the files.
A text file stores textual data.
Binary files can handle binary data.
Binary files use pickle module to store data.
CSV files can handle tabular data.
CSV files can be read easily using CSV reader object.
Program output must be as follows
Total Number of lines are: 7
Total Number of lines starting with A are: 2
Total Number of lines starting with B are: 2
Total Number of lines starting with C are: 2

Aim:

To write a program to count a total number of lines and count the total number of
lines starting with 'A', 'B', and 'C' from the file myfile.txt.
Program:
def lines():
with open(r"F:\SKVV 2022-2023\Class Materials\class 12_Lessons\PRACTICAL 2022-23\SKV 2022-
23\Myfile.txt","r") as f1:
data=f1.readlines()
cnt_lines=0
cnt_A=0
cnt_B=0
cnt_C=0
for lines in data:
cnt_lines+=1
if lines[0]=='A':
cnt_A+=1
if lines[0]=='B':
cnt_B+=1
if lines[0]=='C':
cnt_C+=1
print("Total Number of lines are:",cnt_lines)
print("Total Number of lines strating with A are:",cnt_A)
print("Total Number of lines strating with B are:",cnt_B)
print("Total Number of lines strating with C are:",cnt_C)
lines()
Output:
Total Number of lines are: 7
Total Number of lines starting with A are: 2
Total Number of lines starting with B are: 2
Total Number of lines starting with C are: 2
Result:
Thus, the above program was executed successfully.

b)Write SQL queries on the basis of following table.

Empid EmpName Department Salary Gender


101 Mahesh Finance 32000 M
303 Vijay HR 42500 M
401 Mansha Finance 31500 F
603 Kamal Computer 32150 M
604 Vandana HR 42000 F
631 Sujata Finance 39500 F
i. Delete records of female employees.

ii. Delete all records of Emp table.

iii. Insert a new record with data as 700,’Raman’,’HR’,40000,’M’

iv. Add a new field Phoneno of integer type to table.

vi. Delete records of female employees.

Ans. delete from emp where gender=’F’;

vii. Delete all records of Emp table.

Ans. delete from emp;

viii. Insert a new record with data as 700,’Raman’,’HR’,40000,’M’

Ans. insert into emp values(700,’Raman’,’HR’,40000,’M’);

ix. Add a new field Phoneno of integer type to table.

Ans. Alter table emp add phoneno int;

x. Set the size of EmpName field to 40.

Ans. Alter table emp modify empname varchar(40);

Q-3 a) Write a program to Create a binary file student.dat to hold students’ records like Rollno.,

Students name, and Address using the list. Write functions to write data, read them,

and print on the screen.

Aim:

To write a program to Create a binary file student.dat to hold students’ records like Rollno.,
Students
name, and Address using the list. Write functions to write data, read them, and print on the
screen.
Program:
import pickle
rec=[]
def addrecord():
f=open("student.dat","wb")
rno = int(input("Enter Student No:"))
sname = input("Enter Student Name:")
address = input("Enter Address:")
rec=[rno,sname,address]
pickle.dump(rec,f)
def viewrecord():
f = open("student.dat","rb")
print("*"*78)
print("Data stored in File....")
rec=pickle.load(f)
for i in rec:
print(i)
addrecord()
viewrecord()
Output:
Enter Student No:1
Enter Student Name:Ram
Enter Address:Chennai
******************************************************************************
Data stored in File....
1
Ram
Chennai
Result:
Thus, the above program was executed successfully.
b)Write SQL queries on the basis of following table.

id Name Designation Sal

101 Naresh Clerk 32000

102 Ajay Manager 42500

103 Manisha Clerk 31500

104 Komal Advisor 32150

105 Varun Manager 42000

106 NULL Clerk 32500

i. Count number of records in the table.


ii. Count number of names in the table.
iii. Count number of designations.
iv. Count number of clerks.Q – 2 Practical Report File 7
i. Count number of records in the table.
Ans. select count(*) from employee;
ii. Count number of names in the table.

Ans. select count(name) from employee;


iii. Count number of designations.

Ans. select count(distinct designation) from employee;

iv. Count number of clerks.

Ans. select count(*) from employee where designation=’Clerk’;

Q4.Q-1 a) Write a program to read a text file my_file.txt and display the number of
vowels/consonants/uppercase/lowercase characters in the file.
Aim:
To write a program to read a text file my_file.txt and display the number of
vowels/consonants/uppercase/lowercase characters in the file.
Example:
File Contents as given below
Python is super and trending language.
Allows to store the output in the files.
A text file stores textual data.
Program output must be as follows
Vowels: 35
Consonants: 58
Uppers: 3
Lowers: 87
f=open(r"F:\SKVV 2022-2023\Class Materials\class 12_Lessons\PRACTICAL 2022-
23\SKV 2022-23\my_file.txt")
d=f.read()
v=0
c=0
u=0
l=0
for i in d:
if i.isupper():
u+=1
elif i.islower():
l+=1
if i.lower() in 'aeiou':
v+=1
elif i.isspace():
pass
elif i.lower() not in 'aeiou':
c+=1
print("Vowels:",v)
print("Consonants:",c)
print("Uppers:",u)
print("Lowers:",l)
f.close()
Output:
Vowels: 35
Consonants: 58
Uppers: 3
Lowers: 87
Result:
Thus, the above program was executed successfully.
b)Write SQL queries on the basis of following table.

id Name Designation Sal

101 Naresh Clerk 32000

102 Ajay Manager 42500

103 Manisha Clerk 31500

104 Komal Advisor 32150

105 Varun Manager 42000

106 NULL Clerk 32500


v. Find sum of salaries of all employees.
Ans. select sum(sal) from employee;
vi. Find maximum salary in the table.

Ans. select max(sal) from employee;

vii. Find minimum salary in the table.

Ans. select min(sal) from employee;

viii. Find average salary in the table.

Ans. select avg(sal) from employee;

You might also like