Ayaan Khar-Program File
Ayaan Khar-Program File
COMPUTER SCIENCE
WITH PYTHON
PROGRAM FILE
INDEX
OUTPUT
Q2
Write a code in python for a function void Convert ( T, N) , which repositions all the elements of array
by shifting each of them to next position and shifting last element to first position.
e.g. if the content of array is
0 1 2 3
10 14 11 21
The changed array content will be:
0 1 2 3
21 10 14 11
Sol.
OUTPUT:
Q3
Create a function showEmployee() in such a way that it should accept employee
name, and it’s salary and display both, and if the salary is missing in
function call it should show it as 9000
Sol.
OUTPUT
Q4
Write a program using function which accept two integers as an argument and
return its sum.Call this function and print the results in main( )
Sol.
OUTPUT
Q5
Write a definition for function Itemadd () to insert record into the binary file ITEMS.DAT,
(items.dat- id,gift,cost). info should stored in the form of list.
Sol.
Output
Q6
Write a definition for function SHOWINFO() to read each record of a binary file
ITEMS.DAT,
(items.dat- id,gift,cost).Assume that info is stored in the form of list
Sol.
Output
…
[1, 'pencil', 45.0]
[2, 'pen', 120.0]
…
Q7
Write a definition for function COSTLY() to read each record of a binary file
ITEMS.DAT, find and display those items, which are priced less than 50.
(items.dat- id,gift,cost).Assume that info is stored in the form of list
Sol.
Output
…
[2, 'pen', 120.0]
…
Q8
A csv file counties.csv contains data in the following order:
country,capital,code
sample of counties.csv is given below:
india,newdelhi,ii
us,washington,uu
malaysia,ualaumpur,mm
france,paris,ff
write a python function to read the file counties.csv and display the names of all those
countries whose no of characters in the capital are more than 6.
Sol.
Output
Q9
write a python function to find transfer only those records from the file product.csv to another file
"pro1.csv" whose quantity is more than 150. also include the first row with headings sample of
product.csv is given below:
pid,pname,cost,quantity
p1,brush,50,200
p2,toothbrush,120,150
p3,comb,40,300
p4,sheets,100,500
p5,pen,10,250
Sol.
Output
Q10
write a python function to search and display the record of that product from the file PRODUCT.CSV
which has maximum cost.
sample of product.csv is given below:
pid,pname,cost,quantity
p1,brush,50,200
p2,toothbrush,120,150
p3,comb,40,300
p4,sheets,100,500
p5,pen,10,250
Sol.
Output
Q11
WAP to find no of lines starting with F in firewall.txt
Sol.
f=open(r"C:\Users\hp\Desktop\cs\networking\firewall.txt")
c=0
for i in f.readline():
if(i=='F'):
c=c+1
print(c)
Output:
1
Q12
#WAP to find how many 'f' and 's' present in a text file
Sol.
f=open(r"C:\Users\user\Desktop\cs\networking\firewall.txt")
t=f.read()
c=0
d=0
for i in t:
if(i=='f'):
c=c+1
elif(i=='s'):
d=d+1
print(c,d)
Output
18 41
Q13
Write a program that reads character from the keyboard one by one. All lower case
characters get store inside the file LOWER, all upper case characters get stored inside
the file UPPER and all other characters get stored inside OTHERS.
Sol.
Q14
#WAP to find how many 'firewall' or 'to' present in a file firewall.txt
Sol.
f=open(r"C:\Users\user\Desktop\cs\networking\firewall.txt")
t=f.read()
c=0
for i in t.split():
if(i=='firewall')or (i=='is'):
c=c+1
print(c)
Output
9
Q15
A linear stack called "List" contain the following information:
a. Roll Number of student
b. Name of student
Write add(List) and pop(List) methods in python to add and remove from the stack.
Sol.
Output
Q16
A linear stack called "List" contain the following information:
a. age of student
b. Name of the student
Write enqueue() and dequeue() methods in python to add and remove from the queue.
Sol.
OUTPUT
Q17. Consider the following table GARMENT and FABRIC, Write SQL commands for the statements
(i) to (iv)
TABLE GARMENT
GCODE DESCRIPTION PRICE FCODE READYDATE
10023 PENCIL SKIRT 1150 F 03 19-DEC-08
10001 FORMAL SHIRT 1250 F 01 12-JAN-08
10012 INFORMAL SHIRT 1550 F 02 06-JUN-08
10024 BABY TOP 750 F 03 07-APR-07
10090 TULIP SKIRT 850 F 02 31-MAR-07
10019 EVENING GOWN 850 F 03 06-JUN-08
10009 INFORMAL PANT 1500 F 02 20-OCT-08
10007 FORMAL PANT 1350 F 01 09-MAR-08
10020 FROCK 850 F 04 09-SEP-07
10089 SLACKS 750 F 03 20-OCT-08
TABLE FABRIC
FCODE TYPE
F 04 POLYSTER
F 02 COTTON
F 03 SILK
F01 TERELENE
(i) To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE.
(ii) To display the details of all the GARMENT, which have READYDATE in between 08-DEC-07
and
16-JUN-08 (inclusive if both the dates).
(iii) To display the average PRICE of all the GARMENT, which are made up of fabric with FCODE
as
F03.
(iv) To display fabric wise highest and lowest price of GARMENT from GARMENT table.
(Display
FCODE of each GARMENT along with highest and lowest Price).
Ans . (i) SELECT GCODE, DESCRIPTION
FROM GARMENT ORDER BY GCODE DESC;
(ii) SELECT * FROM GARMENT
WHERE READY DATE BETWEEN ’08-DEC-07’
AND ’16-JUN-08’;
(iii) SELECT AVG (PRICE)
FROM GARMENT WHERE FCODE = ‘F03’;
(iv) SELECT FCODE, MAX (PRICE), MIN (PRICE)
FROM GARMENT GROUP BY FCODE;
Q18 Write SQL commands for (a) to (f) on the basis of Teacher Relation given below:
Teacher Relation
No. Name Age Department Date of join Salary Sex
1. Jugal 34 Computer 10/01/97 12000 M
2. Sharmila 31 History 24/03/98 20000 F
3. Sandeep 32 Maths 12/12/96 30000 M
4. Sangeeta 35 History 01/07/99 40000 F
5. Rakesh 42 Maths 05/09/97 25000 M
6. Shyam 50 History 27/06/98 30000 M
7. Shiv Om 44 Computer 25/02/97 21000 M
8. Shalakha 33 Maths 31/07/97 20000 F
Sol.
(a) SELECT * FROM Teacher
WHERE Department = “History”;
(b) SELECT Name FROM Teacher
WHERE Department = “Hindi” and Sex = “F”;
(c) SELECT Name, Dateofjoin
FROM Teacher
ORDER BY Dateofjoin;
(d) SELECT Name, Salary, Age FROM Teacher
WHERE Age > 23 AND Sex = ‘M’;
(e) SELECT COUNT (*) FROM Teacher
Output
Aarav Shah, 20/216, Joint Secretary, 4000
Arjun Mandal, 19/123, Head Secretary, 4500
Seher Singh, 18/547, Administrator, 6000
Q20
Write a MySQL-Python connectivity code increase the salary(sal) by 300 of those employees
whose designation(job) is clerk from the table emp. Name of the database is “Emgt”
Sol.