You are on page 1of 4

Universal Public School, A Block Preet Vihar, Delhi-92

Class: XII A SUBJECT : COMPUTER SCIENCE

List of Programs for Practical File

Do the following questions in Python and prepare a word file of the code and screenshot of
output.

The program should have the heading – PRACTICAL NO. , the question followed by
the Python Code(on one page). Screenshots of output should be cropped to remove the
unwanted content and placed on a separate page.

1. Write a Python program to capitalize first and last letters of each word of a given string.
2. Write a Python program to remove duplicate characters of a given string.
3. Write a method in Python to find and display the prime numbers from 2 to N. Value of N
should be passed as an argument to the method.
4. Write a method COUNTNOW(PLACES) to find and display those place names in which there
are more than 5 characters after storing the name of places in a dictionary. For example, if
the dictionary PLACES contains:
{‘1’:’Delhi’,’2’:”LONDON’,’3’:’PARIS’,’4’:’NEW YORK’,’5’:’DUBAI’}
The following output should be displayed:
LONDON
NEW YORK
5. Write a program in Python which has following function definitions:
 check_armstrong() which accepts a number and checks whether it is Armstrong or
not.
 reverse_num() which accepts a number and display it in reverse order.
 sum_digits( )which accepts a number an displays the sum of its digits
 check_prime() which accepts a number and checks if it is a prime number or not
 factorial() which accepts a number and displays its factorial
Display a menu for all the functions and call the respective function as per the user’s choice.
6. Write a program in Python which has following function definitions:
 count_vowels() which accepts a string as a parameter and returns the number of
vowels in it.
 count_words() which accepts a string as a parameter and counts and returns the
number of words in it.
 palindrome() which accepts a string as a parameter and checks if it is palindrome or
not.
 delete_char() which accepts a string and character to be removed. The function
should return a new string after deleting all the occurrences of the character from
the string.
 reverse_string() which accepts a strings as an argument and returns the string
after reversing it
Display a menu for all the functions and call the respective function as per the user’s choice.
7. Write a program in Python which has following function definitions:
 min_list() which accepts a list as a parameter and counts and returns the
smallest value in it. (do not use built-in functions)
 search_list() which accepts a list and search number as parameters and returns the
index of the number if it exists in the list.
 Delete_list() which accepts a list and number as parameters and removes the
number from the list
Display a menu for all the functions and call the respective function as per the user’s choice.
8. Write a function compare_numbers() that takes two numbers as arguments and returns the
number that has minimum value at one’s place.
9. Write a function that accepts a list and dictionary as arguments and stores the items of list as
keys of dictionary and their frequencies as the values. The function should return the
dictionary back to the calling program.
10. Write a function LeftShift(lst,x) in Python which accepts numbers in a list lst and shifts all the
elements of the list to the left according to the value of x.
Sample Input Data=[20,40,60,30,10,50,90,80,45,29] where x=3
Output lst=[30,10,50,90,80,45,29,20,40,60]

11. Create a module in Python which has functions for the following:
 Area of Circle
 Area of Square
 Area of Rectangle
Import the module in the Python program which displays the menu for above functions
and calls them.
12. Write a random number generator that generates random numbers between 1 and 6
(simulates a dice).
13. Write a program to display all lines of a text file along with line number.
14. Write a function in Python to count and display the number of lines starting with alphabet ‘A’
present in a text file “Lines.txt”. For example, if the file “Lines.txt” contains the following
lines:
A boy is playing there.
There is a playground.
An airplane is in the sky.
A cricket match is being played.
The function should display the count as 3.
15. Write Python code which reads the contents of a text file and displays each word separated
by #. Also display the total number of words in the file.
16. Write Python code which reads the contents of a text file and removes all the lines that
contain the character 'a' in a file and write it to another file.
17. Write a Python program which accepts the name, class and section of n students and writes
it to a text file. (Use write() function)
18. Write Python code to read the contents of a text file and display the no. of alphabets, digits,
special symbols and spaces in the file.
19. Write a Python program which reads the contents of a text file and displays the number of
vowels and consonants in the file.
20. Write Python code to search and display the names and addresses of persons having age more
than 30 in the data list of persons stored in a text file.
21. Write a program to enter the following information in a binary file:
Item_No, Item_Name,Qty,Price
No. of records to be entered should be accepted from the user. Read the file to display the
records in the following format:
Item No:
Item Name:
Quantity:
Price per Item:
Amount:
22. A binary file ‘STUDENT.DAT’ contains the records of the following type:
[S_Admno, S_Name,Percentage]
Write a menu driven program that has functions for the following:
a) To store records to the file
b) To display the contents of the file
c) To search for a student and display his details
d) To accept a student name and update his percentage ( use seek() and tell())
e) To display the details of students having percentage above 75.
23. A binary file ‘BOOK.DAT’ has the structure [BookNo,BookName,Author,Price].
(i) Write a user defined function CreateFile() to input data for a record and add to BOOK.DAT
(ii) Write a user defined function CountRec(Author) which accepts Author name as parameter
and counts and returns the count of books by the given author stored in the file.
24. A file student.csv stores the following information about students.
[Name, Class, Percentage]. Write a menu driven program that has functions for the following:
(i) To accept the details and store it in the file
(ii) To read the contents of the file and display them
(iii) To display the total no. of records in the file
(iv) To search for a student and display his details otherwise display appropriate message
to the user.
25. Write a function that reads a csv file and creates another csv file with the same content but
with different delimiter.
26. Global Tech plans to develop computerized system for payroll processing. Write Python code
which
(i) Stores the EmpCode,EmpName,Basic Salary, Allowances and Total Salary in a csv file
‘SalaryDetails.csv’.
(ii) Display names of employees who are drawing a salary more than 75000 per month.
(iii) Displays the total salary remitted to its employees.
(iv) Exit the program

You might also like