LIST OF PROGRAMS CLASS XII CS 2024 (1)
LIST OF PROGRAMS CLASS XII CS 2024 (1)
1. Write a function LShift(arr,n) in python which accepts a list arr of numbers and
where n is a numeric value by which all elements of the list are shifted to the left.
Sample input data of the list arr=[10,20,30,40,12,11], n=2
Output arr=[30,40,12,11,10,20]
2. Write a python function string_length() to calculate the length of a string: ‘python
program’
3. Write a python function to count the number of characters (character frequency)
in a string.
Sample string: ‘google.com’
Expected result:{‘g’:2,’o’:3,’l’:1,’e’:1,’.’:1,’c’:1,’m’:1}
4. Write a python function to get a string from a given string where all occurrences
of its first char have been changed to ‘$’,except the first char itself.
Sample string: ‘restart’
Expected result: resta$t
5. Write a function listchange(arr) in python,which accepts a list arr of numbers, the
function will replace the 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,4)
Ouput:[10,10,115,225]
6. Write a function to print even and odd numbers separately from the entered list
by user.
7. Write definition of a method countnow(places) to find and display those place
names in which there are more than characters after storing the name of places
in a dictionary. For example, if a dictionary ‘Places’ contains:
{“1”:”delhi”,”2”:”london”,”3”:”paris”,”4”:”new york”,”5”:”dubai”}
The following output should be displayed:
LONDAN
NEW YORK
8. Write a function, vowelCount() in Python that counts and displays the number of
vowels in the text file named Poem.txt.
9. Write a function in Python to read a text file, Alpha.txt and displays those lines
which begin with the word ‘You’.
10. A list, NList contains following record as list elements: [City, Country, distance
from Delhi] Each of these records are nested together to form a nested list. Write
the following user defined functions in Python to perform the specified operations
on the stack named travel. (i) Push_element(NList): It takes the nested list as an
argument and pushes a list object containing name of the city and country, which
are not in India and distance is less than 3500 km from Delhi. (ii) Pop_element():
It pops the objects from the stack and displays them. Also, the function should
display “Stack Empty” when there are no elements in the stack. For example: If
the nested list contains the following data: NList=[["New York", "U.S.A.", 11734],
["Naypyidaw", "Myanmar", 3219], ["Dubai", "UAE", 2194], ["London", "England",
6693], ["Gangtok", "India", 1580], ["Columbo", "Sri Lanka", 3405]]
The stack should contain:
['Naypyidaw', 'Myanmar'],
['Dubai', 'UAE'],
['Columbo', 'Sri Lanka']
The output should be:
['Columbo', 'Sri Lanka']
['Dubai', 'UAE']
['Naypyidaw', 'Myanmar']
Stack Empty
11. Vedansh is a Python programmer working in a school. For the Annual Sports
Event, he has created a csv file named Result.csv, to store the results of
students in different sports events. The structure of Result.csv is :
[St_Id, St_Name, Game_Name, Result]
Where St_Id is Student ID (integer)
ST_name is Student Name (string)
Game_Name is name of game in which student is participating (string)
Result is result of the game whose value can be either 'Won', 'Lost' or 'Tie' For
efficiently maintaining data of the event,
Vedansh wants to write the following user defined functions: Accept() – to accept
a record from the user and add it to the file Result.csv. The column headings
should also be added on top of the csv file. wonCount() – to count the number of
students who have won any event. As a Python expert, help him complete the
task.
12. Write a function, lenWords(STRING), that takes a string as an argument and
returns a tuple containing length of each word of a string. For example, if the
string is "Come let us have some fun", the tuple will have (4, 3, 2, 4, 4, 3)
13. Write a program to read text line by line using readline() function.
14. Write a program to perform the read and write operations in a text file.
15. Write a program to insert data like-name,class,section in a csv file “new-
sample.csv” without inserting blank rows.
16. Write a program using function to accept characters in a list then find and display
vowels present in the list.
17. Write a function to append data like player_code,player_name,score and rank
etc. into a binary file “sports.dat” .
18. Write a function to read a binary file “sports.dat” and display player code,player
name,score and player rank.
19. Consider a file, SPORT.DAT, containing records of the following structure:
[SportName, TeamName, No_Players] Write a function, copyData(), that reads
contents from the file SPORT.DAT and copies the records with Sport name as
“Basket Ball” to the file named BASKET.DAT. The function should return the total
number of records copied to the file BASKET.DAT.
20. Write a function to search details of the player by their player_code from the
binary file “sports.dat”
21. Write a function to update player name and the score in the binary file
“sports.dat”.
22. Write a function to delete the record of a specific player from the binary file
“sports.dat”
23. Write a function in python that counts the number of “Me” and “My” words
present in a text file “story.txt”. Consider the following story, “story.txt”:
My first book was Me and My family. It gave me a chance to be known to
the world.