0% found this document useful (0 votes)
5 views14 pages

Python Programming Exercises and Solutions

The document contains a series of programming questions related to sorting algorithms, file handling, and data structures in Python. Each question requires the implementation of specific functionalities such as sorting, counting words, handling exceptions, and managing data in files and stacks. The questions cover a range of topics, including bubble sort, insertion sort, file operations, and stack implementations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views14 pages

Python Programming Exercises and Solutions

The document contains a series of programming questions related to sorting algorithms, file handling, and data structures in Python. Each question requires the implementation of specific functionalities such as sorting, counting words, handling exceptions, and managing data in files and stacks. The questions cover a range of topics, including bubble sort, insertion sort, file operations, and stack implementations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Question 1 :

Bubble sort.

OUTPUT:

Question 2 :
Insertion sort.

OUTPUT:
Question 3 :
Write a program to add the content to a file [Link] and display all the
contents.

OUTPUT:

Question 4 :
Write a program to count the number of words in a text file [Link].

OUTPUT:
Question 5 :
Write a program to count ‘to’ in [Link].

OUTPUT:

Question 6 :
Write a program to count the number of lines starting with letter ‘R’ or ‘r’.

OUTPUT:
Question 7 :
Write a program to count the number of alphabets, vowels, digits in [Link].

OUTPUT:
Question 8 :
Write a menu driven program which will do all the operations in a binary file
[Link]. The details of the employee are empno, name, salary, desgn in a
database.
OUTPUT:
Question 9 :
Write a program to enter details of students (roll, name, marks) in a CSV file
[Link] and print all the details.
OUTPUT:

Question 10 :
Write a program to get item details code description and price for multiple items
from the user. Create a CSV file by writing all the item details in one go.

OUTPUT:
Question 11 :
Give one example code to handle IOError. The code should display the message
“file not found” in case of IOError exception and the message “some error
occurred” in case of any other exception.

OUTPUT:

Question 12 :
Give one example code to handle ImportError. The code should display the
message “module is not found” in case of ImportError exception and the
message “some error occurred” in case of any other exception.

OUTPUT:
Question 13 :
Write a program 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 list.
Display a stack if it has at least one element, otherwise display appropriate error
message.

OUTPUT:
Question 14 :
Write a program in python, where MakePush (Package) and MakePop(Package)
to add new package and delete a package from a list of package description,
considering them to act as push and pop operation of the stack data structure.
OUTPUT:
Question 15 :
Write a program to implement a stack for these book_details (book_no,
book_name). That is, now each node of the stack contains two types of
information, a book_no and book_name. Just implement push and display
operation.
OUTPUT:

You might also like