0% found this document useful (0 votes)
4 views3 pages

Solution Practical Question

The document contains multiple Python programming tasks, including counting specific words in a text file, collecting student data and writing it to a binary file, filtering lines from a text file based on word count, and creating a CSV file for user records. Additionally, it includes SQL commands for querying user and item tables, updating item prices, and displaying employee details from given tables. The tasks demonstrate file handling, data serialization, and database operations.

Uploaded by

tkdgurpreet773
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)
4 views3 pages

Solution Practical Question

The document contains multiple Python programming tasks, including counting specific words in a text file, collecting student data and writing it to a binary file, filtering lines from a text file based on word count, and creating a CSV file for user records. Additionally, it includes SQL commands for querying user and item tables, updating item prices, and displaying employee details from given tables. The tasks demonstrate file handling, data serialization, and database operations.

Uploaded by

tkdgurpreet773
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

# a) Write a function in python that counts number of ‘Me’ or ‘My’ word present in a text file ‘bio .txt’.

f=open("[Link]","r")
data=[Link]()
lst=[Link]()
count=0
for i in lst:
if [Link]() in('ME','MY'):
count=count+1
print(" total count of me and my in file ",count)

# b) Write a program to get student data (roll no., name and marks) #from user and write onto a binary file. The
program should be able to get ata from the user and write onto the file as long as the user wants.

# writing on file
import pickle as p
f=open("[Link]","wb")
while True:
l=[]
rn=int(input("enter roll no...."))
name=input("enter name....")
marks=int(input("enter marks...."))
l=[rn,name,marks]
[Link](l,f)
ch=input("wish to add more record y/n....")
if ch=='n':
break
[Link]()
#reading file
f=open("[Link]","rb")
try:
while True:
data=[Link](f)
print(data)
except EOFError:
print("end of file ")
[Link]()

#(c) Write a function in python that reads a text file “[Link]” and print only those line having more than five
words in it.

f=open("[Link]","r")
line=[Link]()
for i in line:
lst=[Link]()
if len(lst)>4:
print(i)
[Link]()
#(d)write a program to create a csv file “[Link]” and enter records with following details Admn , Name, House.
# Writing on file
import csv as c
with open("[Link]","a",newline='') as f:
wr=[Link](f,delimiter=',')
while True:
admn=int(input("enter admn....."))
name=input("enter name.....")
house=input("enter house.....")
l=[admn,name,house]
[Link](l)
ch=input("wish to continue....")
if ch=='n':
break
[Link]()

# Reading file
with open("[Link]","r") as f:
rd=[Link](f)
for i in rd:
print(i)

SQL SOLUTION
Consider the following table ITEM and USER . Write SQL commands for the statement i to iv.
Table: Item

ID ITEM_NAME MAKER PRICE


1 Telcom Powder LAK 1050
2 Face Wash XYZ 2055
3 Bath Shop XYZ 1265
4 Shampoo ABC 3130
5 Face Wash ABC 1095
Table: User

CID C_NAME CITY ID


C1 Rohit Delhi 5
C2 Saket Mumbai 3
C3 Yogesh Delhi 4
C4 Rahul Delhi 5
C5 Dinesh Patna 1

1. To display the details of those user whose city is Delhi.


SELECT * FROM USER WHERE CITY=’DELHI’
2. To display the details of items whose price is more than 1100
SELECT * FROM ITEMWHERE PRICE>1100
3. To increase the price of item by Rs. 50 which id 3.
UPDATE ITEM SET PRICE =PRICE+50 WHERE ID=3
4. To display the C-NAME, CITY and ITEM_NAME where city is Delhi from Tables USER and ITEM.
SELECT USER.C_NAME , [Link] , ITEM.ITEM_NAME
FROM ITEM , USER
WHERE [Link]=[Link] AND [Link]=’DELHI’
Table: Employees

EMPID ENAME Job SAL


010 Meera Manager 70000
105 Ratan Analyst 50000
152 Shekhar Clerk 15000
215 Mohan Foreman 15000
244 Shyam Engineer 30000

Table: Department

DEPT HOD LOCATION EMPID


Finance Hari SEC-A 010
HR Ronan SEC-B 105
Chemical Himanshu SEC-C 152
Electrical Shenoy SEC-B 215
Mechanical Dhruv SEC-C 244

1. To display details of all employees having job Manager from table Employee.
SELECT * FROM EMPLOYEE WHERE JOB=’MANAGER’
2. To increase the salary of clerks by 1000.
UPDATE EMPLOYEES SET SAL=SAL+1000 WHERE JOB=’CLERK’
3. To display the ENAME of employees with their corresponding DEPT, HOD.
SELECT E. ENAME ,[Link], [Link]
FROM EMPLOYEES E , DEPARTMENT D
WHERE [Link]=[Link]
4. To find the total salary of all employees.
SELECT SUM(SALARY ) FROM EMPLOYEES

You might also like