Python Question Bank 2024 New
Python Question Bank 2024 New
Unit-1
Q1. Write a python program for the following.
i) Create list of fruits
ii) Add new fruit in list.
iii) Sort the list.
iv) Delete last fruit name from list.
Q2. What is tuple? What is difference between list and tuple? Explain with example. (IMP)
Q3. What is set? Explain with example with its functions. (V IMP)
Q4. Write a program to check if the input year is leap year or not. Validate the input.
Q5. Write a program that accept the string from user and display the same string after removing
vowels from it or display count of the vowels. (V IMP)
Q6. Write a program to check whether entered string & number is palindrome or not. (V IMP)
Q7. Write a python program
i) To remove all leading ‘zeros’ from an IP address
ii) To find all 5 character long words in a string Accept string from user.
Q8. What is dictionary in python? Explain with examples and any three functions of dictionary.
(V IMP)
Q9. Write a program to create a list of words from the given string which are less than size 'n'.
Input String: "Python programming language has lot of applications in data analytics".
Input n = 8
Q10. Write a program to swap two numbers without using temporary variable accept input from the
user.
Q11. Write a program to find the occurrence and position of the substrings within a string cònsider user
input.
Q12. What is string slice? How it is useful
Q13. Explain deep copy with suitable example.
Q14. Write a Python program to accept a string from the user and convert each last character of
Each word in the given string to uppercase and display the string. (V IMP)
Q15. Write a program to display the fibonacci sequences up to the nth term where n is provided by the
user.
Q16. Write a Python function to accept a string from the user through the main program and
return a number of words in string. (IMP)
Q17. Write a program to find the sum of all Odd numbers and Even numbers from the list where the
list with n elements is to be entered by the user.
Q18. Write a program to reverse each word of “Data.txt” file.
Q19. Develop a program to print the number of lines, words and characters present in the given
file? Accept the file name from user. Handle necessary exceptions.
Q20. Develop a python program to remove the comment character from all the lines in the given
file. Accept the file name from user (VVIMP)
Q21. Write a program to read the contents of file and display occurrence of given character.
(VVIMP)
Q22. Write a program that reads a text file and counts the number of lines and words in the file.
Q23. Write a program to remove all the duplicate items from the list (VVVIMP)
Input List=[10,20,30,20,10,50,60,40,80,50,40]
Output List= [10,20,30,50,60,40,80]
Q24. Write a program to replace digits in a string with their equivalent words (VVIMP)
Input String="Python 3 is 2 easy 4 learning"
Output String="Python three is two easy four learning"
Q25. Create a set containing the elements {1,2,3,4,5} (VIMP)
1) add an element 6 to the set
2) remove the element 2 from the set
3) check if 4 is present in the set
4) find the length of the set
Q26. Write a program to create a tuple by accepting an elements (0-9 or A-Z or a-z) input from
the user 1) display the tuple elements 2) length of tuple 3) count number of digits lowercase
letters and uppercase letters in a tuple (VVIMP)
Q27. Write a Python function compare strings that accept two strings as a Input and compare
Them (VIMP)
Q28. Create generator named "cube" to yield the cube of all numbers from (a) to (b). Test with a
"for" loop and print each of the yeilded values (VVIMP)
Unit-2
Q1. Write a python function to check the given number is even or odd. Handle suitable exceptions.
Q2. Explain the concept of modules and packages with suitable example.(VV IMP)
Q3. What is anonymous function in python? Demonstrate with example. Or Explain lambda with
example. (VV Imp)
Q4. Explain overloading in python with example.
Q5. Write a program to find the factorial of a number using recursion.
Q6. Write a program to print the sum of natural number using recursion.
Q8. Write a program to accept decimal number and print its octal and hexadecimal equivalent.
Q9. Explain positional and keyword arguments in function. Use suitable example.
Q10. Explain Generators in python with suitable example.
Q11. Explain decorators in python with suitable example.(VV Imp)
Q12. Write a Note on : Modules and packages in Python.
Q13. Explain operator overloading in python.
Q14. Write a program to calculate area and perimeter of a circle using functions. Consider the
user for input (IMP)
Q15. Write user defined exception program in python which will except age as an input from the
user and check whether the user is eligible for voting or not. If age<18 it should raise the
exception as ‘NotEligibleForVoting’. (V IMP)
Q16. Write a program to accept an integer number and use try except to catch the exception if a floating
point number is entered.,
Q17. Write a program to create user defined exception NotPrime if given number is not prime else
print the prime number (V IMP)
Q18. create a decorator "smart_multiply" which will add two operands only if they are of the
same data type (i.e the smart multiply) (VVIMP)
Q19. Write a user defined exception program in Python which will find the reverse of a number. if
the number is less than zero it should raise the exception as if the number is less than zero it
should raise the exception as "Invalid input number" (VVIMP)
Q20. Explain the use of any five functions from the Math module with suitable example (VVIMP)
Q21. Write a Python program to subtraction of two matrices using list accept elements for the
matrices from the user (VVIMP)
Unit-3
Q1. Explain constructor and destructor concept in python with example. (VVIMP)
Q2. Explain the terms w.r.t. oops in python.
i) -- lnit-- ii) Self
Q3. What is inheritance? Explain the concept of multiple inheritance with the help of suitable
example. (V IMP)
Q4. What is inheritance? Explain the concept of multilevel inheritance with the help of suitable
example. (V IMP)
Q5. Describe instance variable, static variable and local variables in python object oriented
programming with example. (Imp)
Q6. Create class called, library with data attributes like Acc-number publisher, title and author,
the methods of the class should include (IMP)
(i) Read ( ) - Acc- number, title, author, publisher.
(ii) Compute ( ) - to accept the number of day late, calculate and display the fine charged at
the rate of Rupees 5/- per day.
(iii) Display the data
Q7. Create a class "Bank" having attributes "Bank name" "Branch", "City". "Manager Name" and
methods "Change manager name" and "Display details." Write a constructor-to initialize the
instance variables. Write a main program to demonstrate the use of Bank class.
Q8. Write a program to demonstrate the overriding of the base class method in the derived
Or Explain overriding with suitable example. (V IMP)
Q9. Write a Program for a Bank Account with support for depositMoney, withdrawMoney and
showBalance Operations
Q10. Write a program for extracting email address from a given webpage
Q11. Write a program to validate URL using regular expression. Explain every special character
of the regular expression used in this program. (IMP)
Q12. Write a Python program to check the validity of a password given by user. (VV IMP)
The password should satisfy following criteria:
i) Contain at least 1 letter between a and z
ii) Contain at least 1 number between 0 and 9
iii) Contain at least 1 letter between A and Z
iv) Contain at least 1 character from $, #, @,*
v) Minimum length of password : 8
vi) Maximum length of password : 20
Q13. Write a program to validate email address using regular expression. Also explain the
meaning of each and every special character of the regular expression used by you in this
program. (VVIMP)
Q14. Write a program to validate strong password using regular expression - specify rules for the
strong password. (Imp)
Q15. Write a program to parse the input string for small letters and numbers using regex. (Imp)
Q16. Write a program to validate name of person or username with regex.
Q17. What is synchronization in threading? Explain with example. (IMP)
Q18. Write a multithreading program, where one thread prints square of a number and another
thread prints factorial of a number. Also display the total time taken for the execution.
(VV IMP)
Q19. Write a program to demonstrate: (IMP)
i) Creating a Thread without using any class
ii) Creating a Thread by extending Thread class.
Q20. Write a program for synchronization of threads using RLOCK. Accept the two numbers from user
and calculate factorial of both numbers simultaneously.
Q21. What is thread? Wite a program that creates two threads. One thread should print even
numbers from 2 to 8 and the other should print odd numbers from 1 to 7. (VIMP)
Q22. Explain the concept of delegation. (VVVIMP)
Q22. Write a multithreading program, where where one thread will print factorial of number and
other thread print Fibonacci series using thread synchronization (VVV IMP)
Q23. Write a program to validate PAN card number using regular expression (VVIMP)
Unit-4
Q1. Write a python program to create “employee” collection with fields” (ID, name, address,
Phone, Email and dept) in mongoDB. (V IMP)
Prform the following operations.
i) Display all employees in “Accounts” department
ii) Delete employee with ID - 210345
iii) Update phone with new phone for employee ID -123
Q2. Write a program to retrieve and display employee details from “Employee” collection stored in
mangoDB database.
Q3. Write a program to update the employee details stored in “Employee” collection stored in Mangodb
database.
Q4. Write a python program using MongoDB database to create a "Books" collections having fields:
title, Author (a list), Publisher, PubAddress, (a dict with keys like area, city, country), Price, ISBN.
Accept input from user to insert documents.
Q5. Write a MongoDB program to update the “Books” collection given in above Q4
Q6. Illustrate CRUD operations in MongoDB with example.
Q7. Compare SQL Database with No SQL Database.
Q8. Write a python program to perform following operations. on MongoDB Database. (VIMP)
(i) Create collection “EMP” with fields: Emp-name, Emp- mobile, Emp, sal, Age
(ii) Insert 5 documents.
(iii) Find the employees getting salary between 5000 to 10000.
(iv) Update mobile number for the employee named as “Riddhi”
(v) Display all employees in the order of “Age”
Q9. Write a python program using mongoDB database to create a “student” collection having
fields: Student-ID, Name, Course, Mobile, Address. (a dict with keys like area,city, country,
pin) Accept input from user to insert documents. (VV IMP)
Q10. Write a MongoDB program to delete selected documents given in Q.9 (above program)
Q11. Write à program using mango DB database to create a “employee". Collection having fields Emp
ID, Name, Designation, Mobile, Department. Accept the input from the user to insert the
Documents.
Q12. Write a program using monogo DB database to create a collection “Chess competition" with fieds
(Player_ id, player_name,Player_age,Player_phone) and display all registrations.
Q13. Write a short note on what is Key-Value Database – Couchbase (VIMP)
Q14. Write a short note on Wide-column Databases: Cassandra
Q16. Write a short note on Graph/node Databases: Neo4j
Q17. What is NoSql? Compare SQL Vs NoSQL (VIMP)
Q18. Write a MongoDB program to create an employee collection having fields
EmpID,Name,Salary,Department,Experience
write a code to perform the following operations (VVVIMP)
a) insert five documents into the employee collection
b) retrieve employees working in IT Department
c) retrieve employees whose salary is between 50000 and 80000
d) retrieve employees in descending order of experience
e) update the salary of an employee by 10% whose employee ID is “E101”
f) update the department of an employee whose is name John to HR
g) delete employees having more than 15 years of experience
Q19. Write a MongoDB program to create product collection having fields productID, name,
category, price, stock
write a code to perform the following operations (VVVIMP)
a) insert five documents into the product collection
b) retrieve products belonging to the “Electronics” category
c) retrieve products whose price is between 1000 and 5000
d) retrieve products in ascending order of the stock quantity
e) update the stock of product by 50 units whose productID is "P202"
f) update the category of a product whose name is "Laptop" to computing devices
g) delete products whose stock is less than 10
Unit-5
Q1) create a student model in django that stores information like name, age and course. create the
model and write the migration commands to create the corresponding table in the database
(VIMP)
Q2) write a django view that fetches all student records from the database and renders them on
HTML page. Assume that you have a template students.html to display the records (VIMP)