SENIOR SECONDARY Program List 25-26
Computer Science (083)
1. Input a string S from user. Write user defined functions which accept S as its parameter to:
a) Display whether it is a palindrome or not.
b) Display the string by toggling the case(ie. capital to small and vice versa).
c) Count and display the number of vowels, consonants, uppercase, lowercase characters.
d) Input a character - Split S w.r.t this character.
e) Create and display a new string from S in which the repeated characters from second occurrence
of the character onwards replaced with a ‘#’
2. Write a menu driven program to manipulate a list:
a) Add single element.
b) Add another list to existing list.
c) Delete a given element if it is present in the list.
d) Search a user input element and display it’s frequency.
e) Display all the elements in the same line separated with ‘@’.
f) Arrange the elements in ascending and descending order and display.
3. Consider the following student data:
data = [ ["Alice", 101, [85, 78, 92, 89]], ["Bob", 102, [76, 85, 90, 80]],
["Charlie", 103, [92, 88, 94, 91]], ["David", 104, [60, 72, 70, 65]],…..]
Write Python user defined functions to:
a) Calculate and display each student's average marks.
b) Identify and display the students who have scored below 70 in any subject.
4. Input a list of numbers and test if a number is equal to the sum of the cubes of its digits. Find the
smallest and largest such number from the given list of numbers.
5. Write a program to accept a number n and a base b and convert it to any base number (2,8,16) and
display.
6. Write a user defined function in python to SHIFT (lst) that would accept a list as argument. The function
should shift the negative numbers of the list to right and the positive numbers to left without using a
another list.
Sample List [3, -5, 1, 3, 7, 0, -15, 3, -7, -8]
Output List: [3, 1, 3, 7, 0, 3, -8, -7, -15, -5]
7. Write a user defined function in python to SwapHalfList(Array), which accepts a list Array of numbers
and swaps the elements of 1st Half of the list with the 2nd Half of the list ONLY if the sum of 1st Half is
greater than 2nd Half of the list.(do not use the sum() )
Sample List [ 100, 200, 300, 40, 50, 60]
Output: [40, 50, 60, 100, 200, 300]
8. Write following a user defined function in python to RShift(Lst) in Python, which accepts a list Lst of
numbers shifts all its elements right once.
Sample List [ 10,20,30,40,12,11]
Output: [ 11,10,20,30,40,12]
9. Write following a user defined function in python to LShift(Lst,n) in Python, which accepts a list Lst of
numbers and n is a numeric value by which all elements of the list are shifted to left.
Sample List: [ 10,20,30,40,12,11], n=2
Output: [30,40,12,11,10,20]
10. Write following a user defined function in python to lst_reverse() that reverses a list. Write the code
without slicing/built-in function-33.
Sample list: [12,34,5,67,43] After execution of the code: [43, 67, 5, 34, 12]
11. Write following a user defined function in python to part_reverse(lst,start, end) to reverse elements in a
list where arguments are start and end index of the list part which is to be reversed.
Sample List: [1,2,3,4,5,6,7,8,9,10]
Function Call : part_reverse(my_list,3,6)
1
Output List: [1,2,3,7,6,5,4,8,9,10]
12. Write following a user defined function in python to lst_modify() to read a list of elements. Modify this
list so that it does not contain any duplicate elements i.e. all elements occurring multiple times in the list
should appear only once.
13. Write following a user defined function in python to swap_loc() to swap elements at the even location
with the elements at the odd location.
Sample List: [ 100, 200, 300, 40, 50, 60]
Output List: [200,100,40,300,60,50]
14. Write a user defined random number generator function that generates random numbers between
1 and 6 (simulates a dice) until the user stop the program.(use while loop)
15. Consider the following:
emp = {"John": { "January": 4500, "February": 5200, "March": 4800 },
"Emily": {"January": 6000,”February": 6200,"March": 5800 },…..}
Write Python user defined functions to:
a) Increase the sales by 10% for employees whose average sales exceed 6000.
b) Identify the month in which each employee had their highest sales(display name & month).
c) Display the details of those employees whose name begin with a vowel.
16. Consider the following data format:
{101:['Andrew',78],102:['Mark',99],103:['John',100],...}
Write user defined functions to:
a) Create a dictionary with the roll number, name and marks of n students in a class.
b) display the names of students who have marks above 75.
17. Consider the table MYPET given below. Write a python functions to perform specified operation:
Create_Table() :- to create the table if doesn’t exist, otherwise with proper message.
Add_pet(): - to read input from user and insert the data to the table MYPET.
Display_petdetails(): to read a pet name from user and display its details from table MYPET if it
exists in table, otherwise display an appropriate message.
18. Write a program in python for Sql connectivity Consider tables emp and dept tables:
(a) Add a column HRA with default value 2000
(b) Modify HRA for the employee whose empno is input by the user.
(c) Display name, job and annual salary of employees whose comm is assigned in descending order of
salary. (d) Delete the record of employee whose employee number input by the user
(e) Display empno, name, job and department name who are either a manger or a clerk.
(f) Display minimum and maximum, sum and average of salary along with number of records in job
19. Write functions for Python –Sql Connectivity:
(a) List tables in your database
(b) Create Tables – Garment & Fabric. (Tables given qstn 40)
(c)Display the structure of the table Fabric
(d) Insert a Record by accepting values from user
(e) Delete record of a garment with gcode accepted from the user
(f) Modify the price of a garment with specific gcode accepted from user.
(g) Display records of tables by choice -ie., either records of garment or fabric.
2
20. A list of names is stored in a text file, Names.txt, (1 name per line) but it contains lot of duplicates.
Create a Python function extract_unique_name( ) that extracts all unique names from the text file and
stores them in a list and then print the names in alphabetical order.
Sample input file content:
Amithab
Sharuk
Deepika
Prabhas
amithab
DEEPIKA
Expected output:
['amithab', 'deepika', 'prabhas', 'sharuk']
21. Write a program with user defined functions
CreateWord(()- to create ‘word.txt’ file – by accepting n of lines of text from user and write it into
file using writelines().
DisplayFile()- Display number of characters and number of words in it.
22. Write a program with user defined functions
CreateStory()- n lines accepted from user in a text file story with few lines in it.
DisplayWord()- Display each word separated by a ‘#’
23. Write a program with user defined functions
CreatePledge()- to create pledge.txt, containing few lines of pledge.
DisplayPledge()- Display the contents line by line (after striping leading and trailing
whitespaces) along with number of characters in each line
24. Write a program with user defined functions
CreatePoem()- to create the file poem.txt containing the following :
The woods are lovely
dark and deep
But I have promises to keep
And miles to go before I sleep
And miles to go before I sleep (Note: all lines must be user input)
DisplayPoem()- displays the n most commonly occurring words.
25. Write user-defined functions:
createText() – create the text file wisdom.txt with the following content.
My son, listen to your father's advice.
Don't turn away from your mother's teaching.
What they teach you will be like a beautiful crown on your head.
It will be like a chain to decorate your neck.
(Note: all lines must be user input)
NoVowels() reads the content of the file wisdom.txt and display those words that
doesn’t contain any vowels in it.
vowelWord()- reads the content of the file wisdom.txt displays those lines which have
the second letter of the first word a vowel.
26. Write a program with user defined functions
a) crtBookFile()- for entering details of books from user and insert it in a binary file named
‘book.det through list.
Sample: [Bookid, Bookname, Authorname, Price]
b) BookPrice() –to display book details having price greater than a given price.
c) SearchBook()- Sreach and display the details of a specific book entered by user
27. Write a user defined function:
a) MakeFile () to input multiple items from the user and add to binary file Items.dat which has
structure as [Code, Description, Price].
3
b) SearchRec(Code) in Python which will accept the code as parameter and search and display the
details of the corresponding code on screen from Items.dat. Also display number items
having such code out of total number of items.
28. Write a program with user defined functions
a) CreatEmp()- for entering details of employees from user and insert it in a binary file named
‘emp.dat’ through dictionary. Sample record has the form {empno:[empname,job, sal],
Sample: {101:[Mark,Manager,2000]}
b) DisplayEmps()-Display the records of all employees in tabular form.
c) SearchEmp()-display those employees’ details whose salary is between 25000 and 30000
d) SearchEmpno(eno)- accept the argument and display the record of the employee whose empno is
input by the user.
29. A Binary file, CINEMA.DAT has the following structure:
{'MNO':'m101','MNAME':'Sound of Freedom', 'MTYPE':'Thriller']}
Where, MNO – Movie Number; MNAME – Movie Name; MTYPE is Movie Type
Write a user defined function:
createCinema(): that Adds records the user input data into the binary file.
findType(mtype): that accepts mtype as parameter and displays all the records from the
binary file CINEMA.DAT, that have the value of Movie Type as mtype.
30. Write a program with user defined functions
CreateLogin()- To create a csv file –login.csv that accepts userid, username and age
DisplayDetails() – Display all the records.
SearchLogin()- Accept 2 numbers as lower and upper limit of ages from user. Display the details of all
users whose age in the age limit.
31. Assuming a CSV file students.csv has columns like student_id, name, class,div, subject, score and
grade_level. Write the definition of functions to perform the following.
a) Add_data( filename ) :- accepts a file name as argument and reads input from user and store data
into the file as per format specified.
b) Display_data(filename) :- accepts a filename as argument and reads data from file. Function also
reads subject name, class and div as input from user. Displays the average score by the student
for the subject in the class specified.
32. Anil created a csv file named gadgets.csv to store the details of the gadgets
The structure of gadgets.csv is:
[Deviceno, Name, Price, Brand] - Where, Deviceno is device ID (integer), Name is device name
(string), Price is device price (integer), Brand is device brand (string)
He is now instructed to write the following functions to perform the required operations on csv files.
Newgadget() -to add the details of new gadgets in csv file gadget.csv which stores
records in the format. Deviceno, name, price, brand. Get the input from the user.
Countgadget() - to read the csv file „gadget.csv‟ and display the details of the devices
whose price in the range 1000 to 2500. Also, display the number of such devices.
33. Samantha, a software developer at a company, is tasked with managing a database for employee
performance reviews. She has created a CSV file named "Performance.csv" to store the data. The
structure of "Performance.csv" is as follows:
[Emp_Id, Emp_Name, Project_Name, Review_Result]
Where:
Emp_Id - employee ID (integer)
Emp_Name - employee name (string)
Project_Name - name of the project for the performance review (string)
Review_Result - result of the review, which can be 'Excellent', 'Satisfactory',
or 'Needs Improvement'
Samantha needs to implement the following user-defined functions to efficiently handle
the data:
accept_record() - This function should accept a record from the user, including
employee ID, employee name, project name, and review result, and add it to the
4
"Performance.csv" file. The column headings should also be added on top of the
CSV file.
excellent_count() - Samantha wants a function to count the number of employees
who received an 'Excellent' review for any project. Help Samantha by providing
Python code for these user-defined functions
34. Write a Python menu driven program to implement a stack (LIFO) using a list data structure.
A linear stack called Books contains the following information:
[BookNumber, name of the book and cost of the book]
• PUSH(Books,N) method in python to add N book details each containing the above
mentioned information’s.
• DispStack()- display the stack content in same line
• POP(Book)- pop and display all the elements of the stack and Under Flow when no more
elements to be popped.
35. A list contact contains the following information:
{Eid:[Ename, Phno,Salary]} of Employee
Write a Python menu driven program to implement a stack (LIFO) using a list data structure, stack
status :
PUSH ( ) - To Push an object containing Phone number of Employee and Name of
Employee into the stack.
POP( ) - To Pop an object from the stack and to release the memory
Display() – display details of all Employees
36. Write a function in Python where Book is a stack implemented by a list of books:
(i) PushBook() - to add a new book entry as a record – ie. (book_no, book_title) of Books ,
considering it to act as push operations of the Stack data structure.
(ii) Disp_Stack() – display details of all books
Bookno: Booktitle one after other in different lines
(iii) PopBook() – display a record removed from the stack in the following format:
Bookno: Booktitle
37. Julie has created a dictionary containing names and marks as key value pairs of 6 students. Write a
program, with separate user defined functions to perform the following operations:
● PUSH(R)-Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value (marks) is greater than 75.
● POP()- Pop and display the content of the stack with ‘Under flow’ message when there
are no more elements to be popped.
For example: If the sample content of the dictionary is as follows:
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
The output from the program should be:
TOM ANU BOB OM Under flow
38. Andrew has a list containing 10 integers. You need to help him create a program with separate user
defined functions to perform the following operations based on this list.
● PUSHNums(N)- Traverse the content of the list and push the even numbers into a
stack.
● PopNums()- pop and display the content of the stack.
For Example: If the sample Content of the list is as follows:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be:
38 22 98 56 34 12 Empty Stack
39. Write a function in Python, where Arr is a stack implemented by a list of numbers:
(i) PUSH(L), where L is a list of numbers. From this list push all numbers divisible by
5 into a stack implemented by using a list.
(ii) Display the stack if it has at least one element, otherwise display appropriate
error
5
(iii) POP(), pop and returns top element when ever it is called, returns ‘UnderFlow’ if
the stack is empty.
40. Consider tables Garment and Fabric.
T able: Fabric
Table: Garment
a) Display min, max, sum, and average price for each fabric codes in table Garment.
b) Find the total number of garments in each Type.
c) Increase the price of ‘SLACKS’ by 150.
d) Display fabric code, description, price and type of all garments
e) Display Maximum Fabric code, minimum Ready date.
f) Display different Fabric codes.
g) Display the number of different garment codes.
h) Display number of different Fabric codes.
i) Display the name of garments whose length contains less than 7 characters.
j) Display the name of fabrics ready in 2008.
k) Display Equi-join
l) Display natural join.
6
41. Consider the table Student
a) Modify the id 101 as s107
b) Add columns Tot
c) Modify the column Tot as sum of all subjects(ie., Eng+Phy+Che+Maths+CS) using a query.
d) Add columns Average and Grade.
e) Modify the column Average with Tot/5, assign A+ in column Grade for those students whose
average mark greater than 91.
f) Delete the details of a student in the table whose Tot mark is not assigned.
g) Display the details of the students whose average mark more than 80.
h) Display the min, max, sum, and average of CS marks.
i) Display student ID, Name &marks arranged in descending order of the Average mark.
j) Add the record - 's104','Catherine', 95,76, NULL, 74, 63.
k) Change Che =80 and Grade =’A’ for the student with id s104.
42. Consider Tables EMP and Dept
7
a) Display number of employees, sum and average salary in each department from tables Emp
and Dept.
b) Display Empno, Empname, and Deptno & Dname from tables Emp and Dept.
c) Display number of employees, sum and average salary in each job.
d) Display number of employees, sum and average salary in each job where number of
employees less than 2.
e) Display the name and joining date of senior most employee.
f) Display minimum salary and last hiring date.
g) Display average commission from the table Employee.
h) Display different jobs.
i) Display number of different jobs.
8
43. Consider Tables : Flights & Fares
Write commands to display:
a) Fl_No and No_Flights from Kanpur to Bangalore.
b) Arrange the contents of flights in descending order of Fl_No.
c) Display Fl_No, Airlines and Fare to be paid for the flights from Delhi to Mumbai from
tables flights and Fares where Fare to be paid=Fare+ Fare* Tax/100.
d) Minimum fare Indian Airlines offering from table Fares.
44. Consider Table: Furniture
Write commands to display:
a) information about the Baby Cots
b) Item name which are priced at more than 15000.
c) Item name and Type in which date of stock before 22-01-2002 in descending order of
Item name.
d) Item name and date of stock of those items in which discount percentage is more than
25.
e) Count number of items whose type is ‘sofa’.
f) insert a row: 14, Velvet Touch, Double Bed, 25-03-2003,25000,30
g) Display the number of different types in table furniture.
h) Display the maximum and average discount of the type ‘Baby cot’ and date of stock is less
than ’2002-02-12’;