Python QB
Python QB
QUESTION BANK
MODULE 1
1. Explain if, else and elif flow control statements with suitable examples.
2. Explain the working of while loop with suitable example.
3. Explain the working of for loop with suitable example.
4. Explain break and continue statements in python with examples for each.
5. Briefly explain the working of range() function.
6. Explain with example print(), input(), string replication in python.
7. Write a program in python to find the largest of 3 using elif statement.
8. Discuss exception handling in Python with an example.
9. Explain how to pass parameters in user-defined functions.
8. What is a variable? List the rules to declare a variable in python? Demonstrate the same with
example.
11. Briefly explain the usage of keyword import in python.
12. Explain local and global scope with local and global variables.
13.Demonstrate the Exception handling with a python program to convert Celsius to
Farhenheit.(F=(9/5)*C+32)
14. Explain string concatenation with example.
15.Explain storing of values in python variables.
MODULE 2
1. Define list. How do you create a list? Give examples.
2. Explain the various list methods with examples
3.Explain how tuple is different from a list with suitable example.
4. What are the different ways of deleting elements from a list? Discuss with suitable functions.
5.Write a python program to count the number of occurrences of each letter in the given string
“DEPARTMENT OF CSE”.
6. When do we encounter TypeError, ValueError and IndexError while operating on Lists?
7. Consider the list scores = [5, 4, 7, 3, 6, 2, 1] and write the python code to perform the
following operations:
i) Insert an element 9 at the beginning of the list.
ii) Insert an element 8 at the index position 3 of the list.
iii) Insert an element 7 at the end of the list.
iv) Delete all the elements of the list.
v) Delete an element at the index position 3.
vi) Delete an element at the beginning of the list.
8. For the following three questions, let‟s say bacon contains the list [3.14, 'cat', 11, 'cat', True].
i) What does bacon.index('cat') evaluate to?
ii) What does bacon.append(99) make the list value in bacon look like?
iii) What does bacon.remove('cat') make the list value in bacon look like?
9. Define a dictionary type in Python. Give example.
10.With examples discuss get(),item(),keys(), values() dictionary methods in python.
11.With code snippet explain join() and split() string methods.
12.Develop a python program to repeatedly asks users for their age and password until they
provide valid input.
13.Explain how dictionary is different from list.
14. What are Tuples ? Explain with examples how tuples are created. Compare Tuple with list.
Discuss the following Dictionary operations and functions with examples
1. Accessing , Updating , Deleting , Traversing (Iteration) , Comparing
Module-3
1. Explain assert statement. Illustrate the situation of getting Assertion Error exception.
2. What are regular expressions? Describe question mark, star, plus and dot regex symbols with
suitable python code snippet.
3. Write a program in python that reads a string with five characters which starts with ‘a’ and
ends with ‘z’. Print search successful if pattern matches string.
4. Explain any five character class with example.
5. With code snippet explain saving variables using the shelve module and pprint.pformat()
6.Explain functions of Shutil module with examples.
7.Explain buttons in the Debug control window.
8.What is meant y compressing files? Explain reading, extracting and creating ZIP code snippet.
9.Explain os.path module with examples.
10.Explain the process of reading the file and writing to the files with example.
11.Discuss the following methods of os module i)chdir ii)rmdir iii)walk iv)listdir
12.What is file compression? Explain reading, extracting and creating a Zip file with code
snippet.
Module-4
1. Define class and object. Give an example for creating a class and an object of that class.
2. What are attributes? Explain with an example and draw respective object
diagram.
3. Write a program to create a class called Point with two attributes x and y.
4. Explain class diagrams with example.
5. Explain the _ _init_ _ method with example.
6. With example explain type-based dispatch.
7. Write a program in python to retrieve the current date and print the present day of the
week using datetime module.
8. Write following functions and demonstrate the working of these functions by creating
suitable objects.
To read attribute values
To display point as an ordered pair
To find distance between two points
To find the midpoint of two points
To find reflex of the point about x-axis i.e., it must return a new point
object
Example: point(5,10) -> reflex_x must return a new point (5,-10)
9. Write a program to create a class called Rectangle with the help of a corner
point, width and height. Write following functions and demonstrate their working:
To find and display center of rectangle
To display point as an ordered pair
To resize the rectangle
To find area and perimeter of a rectangle
6. Differentiate copy.copy() and copy.deepcopy() with suitable examples.
7. Differentiate between class variable and instance variable with suitable
examples.
8. Discuss the functions isinstance(),hasattr() with suitable examples.
9. With help of programming examples explain the difference between Prototype and Planned
Programming Development.
Module-5
1.Explain Parsing Html with the beautiful soup module with code snippet for creating ,finding an
element and getting data.
2.What methods do seleniums webelement object have for simulating mouseclick and
keyboardkeys. Explain with python code snippet.
3. Write a python program to access cell in a worksheet.
4. Write a program to get a list of all files with a pdf extension in the current working directory
and sort them.
5. Demonstrate the JSON module with python program.
6. What are the advantages of CSV files? Explain the reader objects and writer objects with
python code.
7. What is web scraping? Explain the following terms webbrowser, Requests, beautiful Soup,
Selenium
8. Explain downloading files from the web with the requests Module
9. Explain saving downloaded files to the Hard Drive
10. Explain creating and saving excel documents in python with an example
11. Explain setting the Font Style of cells in python with example
12. With an code snippet explain extracting Text from PDFs.
13. Explain adding pictures to the word document with code snippet in python