Question Bank Python
Question Bank Python
1. Write a python program to read two integer values and display the result of all
arithmetic operation.
2. Explain single line and multi line comments in python with suitable example.
4 Explain the comparison operators in python with the help of suitable example.
5. Write a python program to display the name and age as follow:
Sample Output:
Good Morning
Enter your name:pqr
Enter your age:25
Hi pqr next year you will be 26
6 Write a python program to check whether the person is eligible to vote or not
Sample Output:
Test Case 1
Enter your age:18
You are eligible to vote
Enter your age:16
You are not eligible to vote
16 Given two integers num1 and num2 perform division in try block. If the division
by zero error occurs print “division by zero is not allowed”
Module 2
1 Explain the concept of list in python by listing out its properties which
distinguish it from tuples.
2 Explain the following list methods with suitable example:
i) append()
ii) extend()
iii) insert()
3 Explain the inbuilt method random.choice() and random.shuffle() performed on
list
4 Write a python program to find the maximum of first and last element in the
list
5 Write a python program to find the sum of list elements
6 Write a python program to demonstrate the working of sort(),reverse()
methods
7. Create a list and count the occurrence of specified element in the list
Sample Output:
[10,20,30,10,20]
Enter Element:10
10 occurs 2 times
8. Explain the 3 ways of creating dictionaries with example for each method
9. Explain the following dictionary methods with examples:
i) .keys()
ii) .values()
iii) .items()
iv) .get()
10. Write a python program to count the number of occurrence of Each character
in a string as a key value pair in dictionary.
11 Write a python program to create a list having multiples of 7
Sample Output:
[7,14,21,28,35,42,49,56,63,70]
12 Create a list of integers and find the sum without using inbuilt function
13 Write a python program to create dictionary using lists
14 Write a python program that asks the user to enter name then:
i) Print the name in Uppercase and lowercase
ii) Print the name in titlecase
Sample TestCase:
Enter Name: Pooja
Uppercase: POOJA
Lowercase: pooja
Module 3
1. List and explain the escape characters used in Python programming
2. What is the purpose of use of raw string.Write a program to obtain the
following output :
That is Carol\’s cat\n I like it
It always\’s grabs the thing\\s
4. WAPP to print the current folder and its corresponding subfolder and files.
Repeat the same task by considering the subsequent to be your current folder
5. WAPP to print all the folders,Subfolders and its files in a ZipFile
6. WAPP to find the size of file and size of compressed file
7. WAPP to extract all the subfolders and its files into current working directory
8. Write a program to print a box using single character with given width and
height.print suitable statements when its not a single character or if width and
height is less than 2.
9. Explain the different logging levels in python.
10 Define Assertions. Demonstrate an example of using assertions in a traffic light
simulation.
11 Explain the functions of the following buttons in Debug control window:
i) Go
ii) Step
iii) Over
iv) Out
v) Quit
12. Demonstrate the use of breakpoints in IDLE’S debugger using suitable program
13. Explain the working of logging.basicConfig() with suitable example.
14. Explain the concept of raising an exception with suitable example
Module 5
1. Explain the concept of classes and objects used in python
2. Write a definition for a class named Rectangle with attributes width and height
3. Explain the attributes with example
4. Write a function called distance_between_points that takes two points as
arguments and returns distance between them by passing instance as an
argument
5. Explain the ways of modifying the state of an object with suitable example for
each of them.
6. Write a function named grow_rectangle that takes a Rectangle and two
attributes width and height .It should modify the width and height of rectangle
7. Demonstrate the concept of shallow copy and deep copy used to copy an
object with a suitable example.
8. write a function called print_time that takes a Time object and prints it in the
form hour:minute:second.
9. Demonstrate the pure functions with suitable example.
10. Use the datetime module to write a program that gets the current date and
prints the day of the week.
11. Develop a program defining str methods for time objects
12. write an add method for Points that works with either a Point object or a tuple
13. Explain the concept of polymorphism in Object oriented programming.
14. Write a definition for a class named Kangaroo with the following methods:
An__init__ method that initializes an attribute named pouch_contents to an
empty list.
15. Explain the following with example:
1.__init__
2.self