cs assignment file
cs assignment file
ASSIGNMENT
(2024-2025)
CLSSS:12
SECTION:E
INDEX
9. To check if the elements in the first half of a tuple are sorted in ascending 9
12. To create a dictionary of phone number and perform the following operation 12
16. To create a random generator that generates random no.’s b/w 1 and 6 17
17. To read a text file line by line and display each word separated by a “#” 18
18. To read a text file and display the count of vowels and consonants in the file 19
19. To get student data(roll no.,name,marks) from user and write in a binary file 20
21. To open file Stu.dat and search for records with roll no. as 12 or 14 22
31. Program to display first three rows fetched from student table 37
32. Python database connectivity script that deletes records from category table 38
PAGE 1
Solution.
SAMPLE RUN:
PAGE2
Q2. WAP THAT RECEIVES TWO NUMBERS IN A FUNCTION AND RETURNS THE
RESULTS OF ALL ARITHMETIC OPERATIONS(=,-,*,/,%) ON THESE NUMBERS.
SOLUTION.
SAMPLE RUN :
PAGE3
SOLUTION.
SAMPLE RUN :
PAGE 4
SOLUTION.
SAMPLE RUN :
PAGE5
SOLUTION.
SAMPLE RUN :
PAGE 6
(i)
SOLUTION.
PAGE 7
SOLUTION.
SAMPLE RUN:
PAGE 8
SOLUTION.
SAMPLE RUN:
PAGE 9
SOLUTION.
SAMPLE RUN :
PAGE 10
SOLUTION.
SAMPLE RUN :
PAGE 11
SOLUTION.
SAMPLE RUN:
PAGE 12
Q 12. WRITE A PROGRAM TO INPUT YOUR FRIENDS’ NAMEA AND THEIR PHONE
NUMBERS AND STORE THEM IN THE DICTIONARY AS THE KEY-VALUE PAIR.
PERFORM THE OPERATIONS ON THE DICTIONARY :
(i) Display the name and phone number of all your friends
(ii) Add a new key-value pair in this dictionary and display the modified dictionary
SOLUTION.
PAGE 13
SAMPLE RUN:
PAGE 14
SOLUTION.
SAMPLE RUN:
PAGE 15
SOLUTION.
SAMPLE RUN:
PAGE 16
SOLUTION.
SAMPLE RUN :
PAGE 17
SOLUTION.
SAMPLE RUN :
PAGE 18
SOLUTION.
SAMPLE RUN :
PAGE 19
Q 18. WRITE A PROGRAM TO READ A TEXT FILE AND DISPLAY THE COUNT
OF VOWELS AND CONSONANTS IN THE FILE.
SOLUTION :
SAMPLE RUN :
PAGE 20
SOLUTION.
SAMPLE RUN :
PAGE 21
SOLUTION :
SAMPLE RUN :
PAGE 22
Q 21. WRITE A PROGRAM TO OPEN FILE Stu.dat AND SEARCH FOR RECORDS
WITH ROLL NUMBERS AS 12 OR 14. IF FOUND DISPLAY THE WORDS.
SOLUTION.
SAMPLE RUN :
PAGE 23
SOLUTION .
SAMPLE RUN :
PAGE 24
SOLUTION :
SAMPLE RUN:
PAGE 25
SOLUTION :
SAMPLE RUN:
PAGE 26
SOLUTION :
SAMPLE RUN :
PAGE 27
SOLUTION :
SAMPLE RUN :
PAGE 28
SOLUTION :
PAGE 29:
SAMPLE RUN:
PAGE 30
SOLUTION :
PAGE 31
PAGE 32
SAMPLE RUN:
PAGE 33
relation Student
WRITE SQL COMMANDS for (a) to (f) and write output for (g).
(b) To list the names of female students who are in Hindi department.
(c) To list names of all students with their date of admission in ascending order.
(d) To display student’s Name , Fee , Age for male Students only.
(f) To insert a new row in the STUDENT table with the following data:
(iv) Select SUM (Fee) from STUDENT where Dateofadm < {01,01,98};
PAGE 34
SOLUTION :
(b) SELECT Name FROM Student WHERE sex= “F” and Department = “Hindi” ;
(d) SELECT Name , Fee , Age FROM Student WHERE Sex = “M” ;
(f) INSERT INTO Student VALUES (9, “Zaheer” , “Computer” , “12/03/97” ,230 , “M” ) ;
Table : BOOKS
Table : ISSUED
Book_Id Quantity_Issued
T0001 4
C0001 5
F0001 2
(a) To show Book name , Author name and Price of books of First Publ. publishers.
(c) To display the names and price from books in ascending order of their price.
(e) To display the Book_Id , Book_Name , and Quantity_Issued for all books which have been
issued.(The query will require contents from both the tables. )
(f) To insert a new row in the table Issued having the following data : “F0003” , 1
(g) Give the output of the following queries based on the above tables :
PAGE 36
(iv) SELECT COUNT (DISTINCT Publishers ) FROM Books WHERE Price >=400 ;
SOLUTION :
(a) SELECT Book_Name , Author_Name , Price FROM Books WHERE Publishers = “First
Publ.” ;
WHERE Books.Book_Id=Issued.Book_Id ;
(g) (i) 5
(ii) 750
(iv) 1
PAGE 37
Q 31. WRITE A PYTHON PROGRAM THAT DISPLAYS FIRST THREE ROWS FETCHED
FROM student table of MySQL databse “test”.
SOLUTION :
SAMPLE RUN :
PAGE 38
SOLUTION :