Professional Documents
Culture Documents
Cs Practical Solution
Cs Practical Solution
iv)Name should be updated as ‘Manish Saini’ and salary as 50000 for employee id
iv. Name should be updated as ‘Manish Saini’ and salary as 50000 for employee id
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.
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,
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.
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.