Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Python Practical Questions

The document outlines a series of practical assignments for Class XII Computer Science, covering topics such as lists, dictionaries, functions, text files, binary files, CSV files, and stacks. Each assignment includes multiple programming tasks in Python, requiring students to implement various functionalities like data manipulation, file handling, and algorithm implementation. The assignments aim to enhance students' programming skills and understanding of data structures and file operations.

Uploaded by

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

Python Practical Questions

The document outlines a series of practical assignments for Class XII Computer Science, covering topics such as lists, dictionaries, functions, text files, binary files, CSV files, and stacks. Each assignment includes multiple programming tasks in Python, requiring students to implement various functionalities like data manipulation, file handling, and algorithm implementation. The assignments aim to enhance students' programming skills and understanding of data structures and file operations.

Uploaded by

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

Class XII Computer Science (083)

Practical Assignment-1(List& Dictionary)

1. Write a Python program to do the following:


a. Create a list of N numbers
b. Input the position of the element to be deleted from the list and delete the element
at the desired position in the list.
c. Input the element and the position where it is to be inserted in the list.
d. Display the list

2. Write a program to read a list of n integers (positive as well as negative). Create two
new lists, one having all positive numbers and the other having all negative numbers from
the given list. Print all the three lists.

3. Write a program in Python to enter the list of N numbers and do the following:
a. Display the list.
b. Display the largest and smallest number in the list.
c. Display the third largest number in the list.
d. Input another list of five numbers and add it with the original list. Display the list.

4. Write a program to read a list of N numbers and display the list in reverse order
without using any function.

5. Write a program to read a list of N numbers and replace odd position element with
even position element. Display the final list.

6. Write a program to read a list of N numbers and replace the even values with
number divided by 2 and odd values with number multiply with 5. Display the final
list.

7. Write a program to input your friend’s names and their phone numbers and store them
in the dictionary as the key-value pair. Perform the following operations on the dictionary:
a. Display the name and phone number for all your friends.
b. Enter the name whose phone number you want to modify. Display the
modified dictionary.

8. Write a program to input roll number and marks obtained in five subjects of N number
of students. Store the data in a dictionary as the key-value pair. Perform the following
operations on the dictionary:
a. Display the roll number and marks obtained in five subjects.
b. Calculate the sum of five subjects and display the roll number and sum of all the
five subjects.

9. Write a program to count the number of times a character appears in a given string.

10. Write a program to convert a number entered by the user into its corresponding number
in words. For example, if the number is 876, then the output should be ‘Eight Seven Six’

11. Write a program in Python to input a number and display whether it is a prime number
or not.

12. Write a program in Python to input a string and display whether it is a palindrome or not.
13. Write a program in python to input two numbers and display the greatest
common divisor.

14. Write a program in Python to input two numbers and display the least common multiple.

15. Write a program in Python to input a number and display whether it is an Armstrong
number or not. An Armstrong number is where number is equal to the sum of cube
of the digits.
16. Write a program in Python that input a number - how many times random number
is generated, and generates random numbers between 1 and 6.

Class XII Computer Science (083)


Practical Assignment -2 (Functions)

1. Write a program in Python using function factorial(n) to calculate and return the
factorial of number n passed to the parameter.

2. Write a program in Python with function sumdigits(n) to calculateand return


the sum of digits of number n passed to the parameter.

3. Write a program in Python with function reverse(n) to calculate and return the
reverse of a number n passed to the parameter.

4. Write a program in Python with function sum(L) to calculate and return the
sum of all the elements in a list.

5. Write a program in Python with function fibo(n) to computer the nth Fibonacci
number.

6. Write a program in Python with function plaindrome(str) to display whether it is


palindrome or not.

7. Write a program in Python with function recgcdf(a, b) to display the


greatest common divisor

8. Write a program in Python with function reclcm(a,b) to display the lowest


common multiple.

9. Write a program in Python with function isprime(n) to display whether it isa prime
number or not.

10. Write a program in Python with function recseries(N) to display the sum ofthe
series S = 12 + 22 + 32 +..................N2
Class XII Computer Science (083)
Practical Assignment -3 (Text File)

1. Write a program in Python to read a file line by line and print it on the screen.
2. Write a program in Python to remove all the lines that contain the character ‘a’ in
a file and write it to another file.
3. Write a function in python to count the number of lines in a text file ‘Story.txt’
which is starting with an alphabet ‘A’.
4. Write a function DISPLAYWORDS() in Python to read lines from a text
file ‘Story.txt’ and display those words, which are less than 4 characters.
5. Write a function in Python to read a text file line by line and display each
word separated by #.
6. Write a function in Python to read a text file and display the number
of vowels/consonants/uppercase / lowercase characters in a file.
7. Write a program in python to read a text file (any phishing email) and find out
most commonly occurring word(s).

Class XII Computer Science (083) 2024-25


Practical Assignment -4 (Binary File)

1. Create a binary file with name and roll number. Search for a given roll number
and display the name, if not found display an appropriate message.
2. Create a binary file with roll number, name and marks. Input the roll number
and update the marks
3. Following is the structure of each record in a data file named “product.dat”
{"prod_code":value, "prod_desc":value, "stock":value}
The values for prod_code and prod_desc are strings, and the value for stock is an
integer.
Write a function in PYTHON to update the file with a new value of stock. The stock
and the product_code, whose stock is to be updated, are to be input during the
execution of the function.
4. Given a binary file “STUDENT.DAT”, containing records of the following
type: [S_Admno, S_Name, Percentage] where S_Admno is the admission
number of student(string), S_Name is the name of the student (string) and
Percentage is the marks percentage of student (float).
Write a function in PYTHON that would read contents of the file
“STUDENT.DAT” and display the details of those students whose percentage is
above 75.
5. Assuming the tuple Vehicle as follows:
( vehicletype, no_of_wheels) where vehicle type is a string and no_of_wheels is an
integer.
Write a function showfile() to read all the records present in an already existing binary
file SPEED.DAT and display them on the screen, also count the number of records
present in the file.
6. Write a function in PYTHON to search for a BookNo from a binary file
“BOOK.DAT”, assuming the binary file is containing the records of the following
type:
{"BookNo":value, "Book_name":value} The BookNo is an integer.

7. Assuming that a binary file VINTAGE.DAT contains records of the following type,
write a function in PYTHON to read the data VINTAGE.DAT and display those
vintage vehicles, which are priced between 200000 and 250000.
[VNO, VDesc, price]

8. Write a function in Python to search for a laptop from a binary file


“laptop.dat” containing records of following type
[ModelNo, RAM, HDD, Details]
Where ModelNo, RAM, HDD are integers and Details is a string.
The user should enter the model number and the function should display the details
of the laptop.

9. Write a function in Python to search for the details of those mobile phones which
have more than 1000 calls from a binary file “mobile.dat”. Assume that binary
file contains records of the following type: (Number, Calls)

10. Write a function in Python to read each record of a binary file “items.dat”, find and
display those items which costs less than 2500. Assume that the file is created with
the help of objects of the following type:
{"ID":string, "GIFT":string, "Cost":integer}

11. Write a function bumper() in Python to read each object of a binary file “gifts.dat”,
find and display details of those gifts, which have remarks as “on discount”.
Assume the file is created with the help of lists of following type:
[ID, Gift, Remarks, Price]
12. Write a Python program to write data into a CSV file named employees.csv. The file
should have columns EmpID, Name, Designation, and Salary.
13. Write a Python program to update the salary of an employee in employees.csv based on
their EmpID.
14. Menu Driven Program:

A school maintains the academic records of students in a CSV file named student_records.csv. The file
contains the following columns:

 StudentID (unique identifier for each student)


 Name
 Class
 Section
 Maths
 Science
 English
 TotalMarks (sum of marks in Maths, Science, and English)

The school administration wants to automate some tasks using Python. You are required to solve the
following problems:

Questions:
1. Data Reading and Displaying

 Question: Write a Python function display_records() that reads the student_records.csv file
and displays all student records in a tabular format.
2. Adding a New Record

 Question: Write a Python function add_student() that takes student details as input (except
TotalMarks) and adds a new record to the student_records.csv file. Ensure that the TotalMarks
field is calculated and added automatically.

3. Updating Marks

 Question: Write a Python function update_marks(student_id, subject, new_marks) that updates


the marks of a specific student in a specific subject. Recalculate the TotalMarks for that student
after updating the marks.

4. Ranking Students

 Question: Write a Python function rank_students() that reads the student_records.csv file and
displays the top 3 students based on TotalMarks.

5. Searching for a Student

 Question : Write a Python function search_student(student_id) that searches for a student by


their StudentID and displays their details.
Class XII Computer Science (083)
Practical Assignment-5 (Stack)

1. Write a program in python to implement queue with the following functions:


● INSERTQ(Arr, data) for insertion operation
● DELETEQ(Arr) for deletion operation
● Exit
Arr is the list used for implementing queue and data is the value to be inserted.

2. Write a function in python to implement stack with the following functions:


● MakePush(Package) for push operation
● MakePop(Package) for pop operation
● Exit
A Package is the list of package description.

3. Write a program in Python to implement a stack of book details – book no, book
name and do the following:
● Add the book details
● Delete the book details
● Display all the records
● Exit

4. Write a function in Python PUSH(Arr), where Arr is a list of numbers. From this list push all
numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at
least one element, otherwise display appropriate error message

5. Vedika has created a dictionary containing names and marks as key-value pairs of 5 students.
Write a program, with separate user-defined functions to perform the following operations:

Push the keys (name of the student) of the dictionary into a stack, where the corresponding
value (marks) is greater than 70.

Pop and display the content of the stack.

You might also like