Python Unit-5 Previous Questions
On this page
- SEMESTER END EXAMINATIONS – JUNE 2024
- BACKLOG SUBJECT EXAMINATIONS – SEPTEMBER / OCTOBER 2023
- SEMESTER END EXAMINATIONS – MAY / JUNE 2023
- SUPPLEMENTARY SEMESTER EXAMINATIONS – SEPTEMBER 2022
- SUPPLEMENTARY SEMESTER EXAMINATIONS - NOVEMBER 2022
- SEMESTER END EXAMINATIONS – JUNE 2022
- EXAMINATIONS SEPTEMBER /OCTOBER 2021 SUPPLEMENTARY
- EXAMINATIONS SEPTEMBER /OCTOBER 2021 SUPPLEMENTARY
- EXAMINATIONS SEPTEMBER /OCTOBER 2020 SUPPLEMENTARY
- SEMESTER END EXAMINATIONS – JUNE 2019
- SUPPLEMENTARY SEMESTER EXAMINATIONS – JULY 2019
- MAKEUP EXAMINATIONS – JULY 2019
- SEMESTER END EXAMINATIONS – MAY/JUNE 2018
- SUPPLEMENTARY SEMESTER EXAMINATIONS – JULY/AUGUST 2018
- SEMESTER END EXAMINATIONS – MAY/JUNE 2017
SEMESTER END EXAMINATIONS – JUNE 2024
List and describe ANY FIVE file open modes in python.
Explain exception handling in python in detail with the help of an example.
Develop a python program that will prompt the user for a file name, read all the numbers from the file into a list, separate positive and negative numbers from the list, and store them in separate files.
Write a program that will prompt the user for a file name, read all the lines from the file into a list, sort the list, and then print the lines in sorted order.
Discover what exception is produced by each of the following points. Then develop small example program that illustrates catching the exceptions using try statement(s) and continuing with execution after the interrupt.
- Division by zero
- Opening a file that does not exist
- Indexing a list with an illegal value
BACKLOG SUBJECT EXAMINATIONS – SEPTEMBER / OCTOBER 2023
Illustrate “catching an exception is programmatically good and necessary mechanism” with exception handling mechanism in python. Demonstrate the working of any six exceptions in python.
Discuss all the file accessing modes and also write python program to count the number of words, characters and lines from the files and also copy the contents of the file into another file.
Illustrate user defined exceptions with suitable examples.
SEMESTER END EXAMINATIONS – MAY / JUNE 2023
Demonstrate the methods to read and write text files in python.
List and describe the file open modes in python.
Explain exception handling in python with an example.
SUPPLEMENTARY SEMESTER EXAMINATIONS – SEPTEMBER 2022
Develop a script that will prompt the user for a file name, read all the lines from the file into a list, sort the list, then print the lines in sorted order as well as write to a file.
How do you handle an exception? Explain all the three keywords in exception handling. Write a simple program to show how an except clause is used for handing multiple exceptions.
Discover the exception produced by each of the following points. Then, for each, develop a small script that illustrates catching the exception using a try statement and continuing with execution after the interrupt. i) Division by zero ii) Opening a file that does not exist iii) Indexing a list with an illegal value iv) Using improper key with a dictionary v) Using un-indented code.
SUPPLEMENTARY SEMESTER EXAMINATIONS - NOVEMBER 2022
Develop a Python program to demonstrate user defined exception.
Write a program that will prompt the user for a file name, read all the lines from the file into a list, sort the list, and then print the lines in sorted order.
List and describe different file open modes in python.
Construct a python program to read a text file and display first 5 lines and last five lines.
Discover what exception is produced by each of the following points. Then, for each, write a small example program that illustrates catching the exception using a try statement and continuing with exception after the interrupt. i. Division by zero ii. Opening a file that does not exist iii. Indexing a list with an illegal value iv. Using an improper key with a dictionary v. Passing an improperly formatted expression to the function expr( )
SEMESTER END EXAMINATIONS – JUNE 2022
Develop a script that will prompt the user for a file name, then print all lines from the file that contain the Python comment character #.
List and describe the file open modes in python.
Explain user defined exceptions in python with an example.
Develop a script that asks the user for a file name, then prints the number of characters, words and lines in the file.
EXAMINATIONS SEPTEMBER /OCTOBER 2021 SUPPLEMENTARY
Develop a python script that will prompt the user for a string and a file name, and then print all lines in the file that contains the string entered by the user.
How do you handle an exception? Demonstrate try-finally clause.
Discover the exception produced by each of the following points. Then, for each, develop a small script that illustrates catching the exception using a try statement and continuing with execution after the interrupt. i) Division by zero ii) Opening a file that does not exist iii) Indexing a list with an illegal value iv) Using improper key with a dictionary v) Using unindented code.
EXAMINATIONS SEPTEMBER /OCTOBER 2021 SUPPLEMENTARY
Demonstrate the methods to read and write text files in python.
List and describe the file open modes in python.
Explain exception handling in python with an example.
Write a python program to sort the file contents in reverse order and write the sorted contents along with line number.
EXAMINATIONS SEPTEMBER /OCTOBER 2020 SUPPLEMENTARY
What is exception handling? How do you handle exceptions in python? Explain with an example.
Explain the different methods available for manipulating the text files.
SEMESTER END EXAMINATIONS – JUNE 2019
Consider the following program which contains some errors. You may assume that the comments within the program accurately describe the program’s intended behavior.
# Get two numbers from the user
n1, n2 = eval(input()) # 1
# Compute sum of the two numbers
print(n1 + n2) # 2
# Compute average of the two numbers
print(n1+n2/2) # 3
# Compute a quotient
print(n1/d1) # 4
# Compute a product
n1*n2 = d1 # 5
For each line listed in the comments, indicate whether or not an interpreter error, run-time exception, or logic error is present. Not all lines contain an error.
Why is exception handling required? Write a Python program to demonstrate user defined exception.
List the various methods to read and write the file contents and Explain.
Construct a python program to read a text file and display first 5 lines and last five lines.
Consider the following file num_pairs.txt
, read data and find the line total and write the line as well as total to a new file.
num_pairs.txt
1.3 3.4
2 4.2
-1 1
SUPPLEMENTARY SEMESTER EXAMINATIONS – JULY 2019
Develop a python program that will prompt the user for a file name, read all the numbers from the file into a list, separate positive and negative numbers from the list, and store them in separate files.
Discover the exception produced by each of the following points. Then, for each, develop a small script that illustrates catching the exception using a try statement and continuing with execution after the interrupt. i) Division by zero ii ) Opening a file that does not exist iii) Indexing a list with an illegal value iv) Using improper key with a dictionary v) Using unindented code.
MAKEUP EXAMINATIONS – JULY 2019
Discover what exception is produced by each of the following points. Then, for each, write a small example program that illustrates catching the exception using a try statement and continuing with exception after the interrupt. i. Division by zero ii. Opening a file that does not exist iii. Indexing a list with an illegal value iv. Using an improper key with a dictionary v. Passing an improperly formatted expression to the function expr( )
Write a program that will prompt the user for a file name, read all the lines from the file into a list, sort the list, and then print the lines in sorted order.
SEMESTER END EXAMINATIONS – MAY/JUNE 2018
Explain with the help of an example the different functions used with files.
Write a program that asks the user for a file name, then prints the number of characters, words and lines in the file.
Explain exception handling in python in detail with the help of an example.
SUPPLEMENTARY SEMESTER EXAMINATIONS – JULY/AUGUST 2018
Why is exception handling required? Write a Python program to demonstrate user defined exception.
List the various methods to read and write the file contents and Explain.
Construct a python program to read a text file and display first 5 lines and last five lines.
Consider the following file “num_pairs.txt”, read data and find the line total and write the line as well as total to a new file.
num_pairs.txt
1.3 3.4
2 4.2
-1 1
SEMESTER END EXAMINATIONS – MAY/JUNE 2017
Develop a script to open a file and count number of lines in the file. Find the middle 3 lines in the file and write it on to another file. Repeat the same steps until there are only 3 lines are left.
Develop a program that asks the user for a file name, then prints the number of special characters, words and lines in the file.
Explain exception handling in python in detail with the help of an example.