Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Index: S.nO Questiones 1 2

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

Index

S.nO Questiones Page


no.
Program to generate Fibonacci series
1 in a tuple
Write a python function to count the
2 number of characters (character
frequency) in a string.
Sample Result : ‘google.com’
Expected Result :{‘g’:2, ‘o’:3, ‘l’:1, ‘e’:1,
‘.’:1, ‘c’:1, ‘m’:1

Write a Python program to remove


3 duplicates from a list.
a = [10,20,30,20,10,50,60,40,80,50,40]
Write a function listcharge(Arr) in
4 Python, which accepts a list of
numbers and replace each even
number by value 10 and multiply odd
number by 5.
Sample Input Data of the list is:
a = [10,20,23,45]
listchange(a)
Output: [10,10,115,225]

Write a Python program to reverse a


5 string.
Sample String :- “python123”
Expected Output:- “321nohtyp”

Write a Python function that accepts a


6 string and calculates the number of
uppercase letters and lowercase
letters.
Sample String : Python Programming
Write a Python function to check a
7 number is perfect or not . According to
Wikipedia, in number theory , a perfect
number is a positive integer that is
equal to the sum of its proper positive
divisors, that is , the sum of its positive
divisors excluding the number itself
(also known as its aliquot sum).
Equivalently, a perfect number is a
number that is half the sum of all of its
positive divisors (including itself)
Write a program that perform that
8 performs the following operation on a
string.
Write a menu-driven program to
9 perform all the basic operations using
dictionary on student binary file such
as inserting reading, updating,
searching and deleting a record.
Write a method write1() in Python to
10 write multiple lines of text contents into
a text file ‘daynote.txt’.
Write a function countmy() in python to
11 read the text file “DATA.TXT” and
count the number of times “my” occurs
in the file . For example, if the file
“DATA.TXT” contains – “This is my
website. I have displayed my
preferences in the CHOICE section.”-
the countmy( ) function should display
the output as :
“my occurs 2 times”.

Write a code to print just the last line of


12 a text file ‘ data.txt’ along with total
lines in a text file.
Write a menu-driven program to
13 perform read and write operations
using a text file called “student.txt”
containing student roll_no, name and
address using two separate functions
are given below:
Write a menu-driven program
14 implementing user-defined functions to
perform different functions on a csv file
“student” such as.
Write a program to create a stack
15 called Employee, to perform the basic
operation on stack using list. The list
contains the two values-employee
number and employee name. The
program should include the options for
addition, deletion and display of
employee details.
Write a function in
16 Python,Push(Student) where Student is
a dictionary containing the details of
Student name:
Marks_obtained
{Sname: Marks}
The function should push the names of
those student in the stack who have
scored who have scored greater than
75. Also, display the count of elements
pushed into the stack.
WAP to create database and table with
17 the following details.
Insert 2 records in the above created
18 table using four parameterized query
methods.
WAP to display all records (one by one)
19 from the table created in Q no 17.
WAP to calculate and print TotalPoints
20 (multiply by 2 on each win) from the
same table.
Write SQL commands for (a) to (f) on
21 the basis of the table SPORTS:
Study the following table and write SQL
22 queries for questions (i) to (iv) and
output for (v) and (vi).
Navdeep creates a table RESULT with
23 a set of records to maintain the marks
secured by students Sem1, Sem2,
Sem3 and their division. After creation
of the table, he has entered data of 7
students in the table.
Based on the given data given above
answer the following questions:
Q24.a)Consider the following tables –
24 CARDEN and CUSTOMER:
What will the output of the following
statement?
SELECT * FROM CARDEN, CUSTOMER;
b)Write the output of the queries(i) to
(iv) based on the table STOCK given
below:
CERTIFICATE
This is to certify that saransh
bansal of XII-A Science, Ramjas
School , have successfully complet
ed her project in computer science
practicals as prescribed by CBSE
in the year 2023-24.

Internal Examiner Sign.


QUES) WAP TO GENERATE FIBONACCI SERIES IN A TUPLE

---------------------------------------------------------------------------------------------------------------------------------------------------------------

SOLUTION)

OUTPUT)
QUES 2) WAF TO COUNT THE NUMBER OF CHARACTERS IN
STRING.

SOLUTION)

OUTPUT)
QUES3)WAP TO REMOVE DUPLICATES FROM A LIST.

a=[10,20,30,20,10,50,60,40,80,50,40]

SOLUTION)

OUTPUT)
QUES4)WAF listchange(Arr) in python, which accepts a list of numbers and replace each even number by value 10
and multiply odd number by 5.

SOLUTION:

OUTPUT:
QUESTION 5: WRITE A PYTHON PROGRAM TO REVERSE A STRING.

SOLUTION:

OUTPUT:
QUESTION 6: WAF THAT ACCEPTS A STRING AND CALCULATES THE NUMBER OF UPPERCASE AND LOWECASE
LETTERS.

SOLUTION:

OUTPUT:
QUESTION 7:WAF TO CHECK WHTHER A NUMBER IS PERFECT OR NOT.

SOLUTION:

OUTPUT:
QUESTION 8: WAP THAT PERFORMS THE FOLLOWING OPERATIONS IN A STRING:

I)PROMPT THE USER TO INPUT A STRING

II)EXCTRACT ALL THE DIGITS FROM THE STRING, IF THERE ARE DIGITS IN THE INPUTTED STRING

III)CALCULATE AND DISPLAY THE SUM OF DIGITS, ALSO DISPLAY

1)THE ORIGINAL STRING

2)THE DIGITS

3)THE SUM OF DIGITS

IV)IF THERE ARE NO DIGITS:


1)DISPLAY THE ORIGINAL STRING ALONG WITH THE APPROPRIATE MESSAGE:”No Digits are present”

SOLUTION:

OUTPUT:
QUESTION 9) WRITE A MENU=DRIVEN PROGRAM TO PERFORM ALL THE BASIC OPERATIONS USING DICIONARY ON A
STUDENT BINARY FILE SUCH AS INSERTING, READING, UPDATING, SEARCHING AND DELETING A RECORD.

SOLUTION:
OUTPUT:
QUESTION 10: WRITE A METHOD WRITE1() IN PYTHON TO WRITE MULTIPLE LINES OF TEXT CONTENTS INTO A TEXT
FILE “daynote.txt”.

SOLUTION:

OUTPUT:
QUESTION 11: WRITE A FUNCTION COUNTMY() IN PYTHON TO READ THE TEXT FILE “DATA.TXT” AND COUNT THE
NUMBER OF TIMES “my” OCCURS IN THE FILE.

TEXT IN DATA.TXT- “This is my website.I have displayed my preferences in the CHOICE section.”

SOLUTION:

OUTPUT:
QUES 12: WAP TO PRINT JUST THE LAST LINE OF TEXT FILE “DATA.TXT” ALONG WITH TOTAL LINES IN A TEXT FILE.

SOLUTION:

OUTPUT:
QUESTION 13:

WRITE A menu-driven program to perform read and write operations using a text file called "student.txt" containing
student roll_no,name and adress using two separate functions as given below

1)student_record(filename)-entering student details

while writing into a file(Student.txt), the roll_no field will be separated from the remaining fields with a comma
separator.

2)student_readdata(filename)-display student details

3)student_search(filename)-search a student on the basis of roll_no

SOLUTION:
QUESTION 14: write a menu driven program implementing user defined functions to perform different functions on a
csv file "student" such as:

a)write a single record to csv

b)write all the records in one single go onto the csv

c)display the contents of csv file

SOLUTION:
QUESTION 15: WRITE A PYTHON PROGRAM TO IMPLEMENT ALL BASIC OPERATIONS OF A STACK, SUCH AS ADDING
ELEMENT(PUSH OPERATION), REMOVING ELEMENT(POP OPERATION) AND DISPLAYING THE STACK
ELEMENTS(TRAVERSAL OPERATIONS) USING LISTS.

SOLUTION:

OUTPUT:
QUESTION 16: write a program to perform insert and delete operations on a queue containing members deltails as
given in following definition of item node:

member no-integer

membername-string

age=integer

SOURCE CODE:
Q17. WAP to create database and table with the following
details:
Database name – CWC2023
Table name – POINTS
Columns – TeamName varchar(20), P int, W int, L int
SOLUTION)

OUTPUT:
. Insert 2 records in the above created table
QUES 18)

using four parameterized query methods.

SOLUTION:

METHOD 1-USING EXECUTE() WITH TUPLE:

METHOD 2-USING EXECUTEMANY() WITH LIST OF TUPLES:

METHOD 3:USING EXECUTE() WITH DICTIONARY:

METHOD 4:USING EXECUTEMANY() WITH LIST OF DICTIONARY:


Q19)WAP to display all records (one by one)
from the table created in Q no 17.
Solution:
Q20)WAP to calculate and print TotalPoints
(multiply by 2 on each win) from the same table.
Q21) Q21. Write SQL commands for (a) to (f) on the
basis of the table SPORTS:

a) Display the names of the students who have


grade ‘C’ in either Game1 or Game2 or both
Ans.SELECT Name FROM SPORTS WHERE
Grade1= ‘C’ OR Grade2= ‘C’;
b) Display the number of students getting
grade ‘A’ in Cricket.
Ans. SELECT COUNT(*) FROM SPORTS WHERE
(Grade1= ‘A’ AND Grade2 = ‘A’) AND ( Game1 =
‘Cricket’ OR Game2 = ‘Cricket’);
c) Display the names of the students who have
the same game for both Game1 and Game2.
Ans. SELECT Name FROM SPORTS WHERE
Game1 = Game2;
d) Display the game taken up by the students,
whose name starts with ‘A’.
Ans. SELECT Game1, Game2 FROM SPORTS
WHERE Name LIKE "A%";
e) Add a new column named ‘Marks’.
Ans. ALTER TABLE SPORTS ADD (Marks
INT(4));
f) Assign a value 200 for marks for all those
who are getting grade ‘B’ or grade ‘A’ in
both Game1 and Game2.
Ans. UPDATE SPORTS SET Marks = 200 WHERE
(Grade1="A" OR Grade2="A") or (Grade1="B" OR
Grade2="B");
Q22. Study the following table and write SQL queries
for questions (i) to (iv) and output for (v) and (vi).

i) Write SQL query to display Pname,Quantity and


Rate for all the orders that either Pencil or Pen.
Ans. SELECT Pname,Quantity,Rate FROM ORDERS
WHERE Pname IN ("Pencil","Pen");
ii) Write SQL query to display the orders which are
not getting any Discount.
Ans. SELECT * FROM Orders WHERE Discount IS
NULL;
iii) Write a SQL query to display the Pname,Quantity
and Sale_date for all the orders whose total cost
(Quantity * Rate) is greater than 500.
Ans. SELECT Pname, Quantity,Sale_date FROM
Orders WHERE Quantity*Rate>500;
iv) Write SQL query to display whose Rate is the
range 20 to 100.
Ans. SELECT * FROM Orders WHERE Rate BETWEEN
20 AND 100;
v) SELECT Pname,Quantity FROM ORDERS WHERE
Pname LIKE("_e%");
Ans.

vi) SELECT Pname,Quantity FROM ORDERS ORDER


BY Quantity desc;
Ans.
Q23. Navdeep creates a table RESULT with a set of
records to maintain the marks secured by students
Sem1, Sem2, Sem3 and their division. After creation of
the table, he has entered data of 7 students in the table.

Based on the given data given above answer the


following questions:
(i) Identify the most appropriate column, which can
be considered as Primary key.
Ans. Roll_NO
(ii) If two columns are added and 2 rows are deleted
from the table result, what will be the new degree
and cardinality of the above?
Ans. New Degree : 8
(iii) Write the statements to:
a) Insert the following record into the table –
Roll No – 108, Name – Aadit, Sem1- 470,
Sem2 – 444, Sem3 – 475, Div – I.
Ans. INSERT INTO RESULT VALUES(108,
“Aadit”, 470, 444, 475, 1);
b)Increase the SEM2 marks of the students by
3% whose name begin with ‘N’.
Ans. UPDATE RESULT
SET SEM2=SEM2+(SEM2*0.03)
WHERE SNAME LIKE “N%”;
(iv) Write the statements to:
a) Delete the record of students securing IV
division.
Ans. DELETE FROM RESULT WHERE DIV= ‘IV’;
b)Add a column REMARKS in the table with
datatype as varchar with 50 characters.
Ans. ALTER TABLE RESULT ADD(REMARKS
VARCHAR(50));
Q24.a)Consider the following tables – CARDEN and
CUSTOMER:
Table : CARDEN

Table : CUSTOMER

What will the output of the following statement?


SELECT * FROM CARDEN, CUSTOMER;

OUTPUT:-
b)Write the output of the queries(i) to (iv) based on the
table STOCK given below:

i) SELECT Dcode,MAX(UnitPrice) FROM STOCK


GROUP BY Dcode;
Ans.
ii) SELECT COUNT(DISTINCT Dcode) FROM
STOCK;
Ans.

iii) SELECT Qty*UnitPrice FROM STOCK WHERE


ItemNo=5006;
Ans.

iv)SELECT MIN(StockDate) FROM STOCK;


Ans.
Acknowledgement
I would like to express my gratitude
to my Computer Science teacher Mr.
Nitin Wadhwa for his guidance and
support throughout the completion
of this Computer Science practical
file. His expertise and valuable
feedback have been instrumental in
enhancing my understanding of the
concepts covered. I also extend my
thanks to my peers for collaborative
efforts and the resources provided
by the department.

You might also like