0% found this document useful (0 votes)
49 views

LIST OF PROGRAMS CLASS XII CS 2024 (1)

Uploaded by

potatotify0550
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

LIST OF PROGRAMS CLASS XII CS 2024 (1)

Uploaded by

potatotify0550
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

LIST OF PROGRAMS CLASS XII CS 2024-25

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.

The output of the function should be :


Count of Me/My in the file: 4
24. Write a function in python to count the number of lines in a text file “My_story.txt”
that are starting with an alphabet “A”.
25. Write a function ‘display_words()’ to read lines from a text file ‘poem.txt’, and
display those words, which are less than 4 characters.
26. Write a function in python to count and display the total number of words in a text
file.
27. A binary file “book.dat” has structure [BookNo, BookName,Author,Price]:
a. Write a user defined function createFile() to input data for a record and
add to book.dat
b. Write a function coutnRec(Author) in python which accepts the Author
name as parameter and count and return the number of books by the
given Author are stored in the binary file “book.dat”.
28. Write a program to copy the data from “data.csv” to “temp.csv”.
29. A binary file “student.dat” has the structure [Adm_No,Name,Percentage]. Write a
function countrec() in python that would read contents of the file “student.dat” and
display the details of those students whose percentage is above 75. Also, display
the number of students who have scored above 75%.
30. Write a menu based program to add, delete and display the record of hostel
using list as stack data structure in Python. The record of hostel contains the
fields: Hostel number, Total Students and Total Rooms.
31. Write a push(arr) function, where arr is a list of numbers. From this list push all
the numbers divisible by 5 onto a stack implementation by using a list. Display
the stack, if it has at least one element, otherwise display an error message.
32. Write push(student) and pop(student) functions to add a new student name and
remove a student name from a stack student.

You might also like