23CS201 – Python Programming
Question Bank
UNIT I – DATA TYPES, EXPRESSIONS, STATEMENTS
Two Mark Questions:
● What is the purpose of the Python interactive mode?
● Define variable and give an example.
● List any two basic data types in Python.
● What is the difference between `int` and `float`?
● Define a tuple with an example.
● What is the precedence of operators?
● How do you write a comment in Python?
● Write a Python statement to exchange values of two variables.
● What is the role of `input()` in Python?
● List the types of statements in Python.
Sixteen Mark Questions:
1. Explain the various data types available in Python with examples.
2. Write a program to swap values of two variables without using a third variable.
3. Discuss precedence and associativity of operators in Python.
4. Explain the process of debugging and common errors in Python.
5. Write a program to calculate the distance between two points.
UNIT II – CONTROL FLOW, FUNCTIONS, STRINGS
Two Mark Questions:
● What is the purpose of `if` statement in Python?
● Define recursion.
● Differentiate between `break` and `continue`.
● What is the use of `elif`?
● Mention any two string methods.
● Define function parameters.
● What is the difference between local and global variables?
● What is the use of `while` loop?
● Define immutability in strings.
● What is the use of `return` in a function?
Sixteen Mark Questions:
6. Explain control flow statements in Python with examples.
7. Write a recursive function to calculate factorial of a number.
8. Discuss string slicing and string methods with code snippets.
9. Write a Python program to check whether a given number is prime or not.
10. Explain function definition, parameters, return values, and recursion with
examples.
UNIT III – LISTS, TUPLES, DICTIONARIES
Two Mark Questions:
● Define a list with example.
● How do you append an element to a list?
● Differentiate between list and tuple.
● What is a dictionary in Python?
● How do you slice a list?
● What is the use of `len()`?
● Define aliasing in list.
● Write a statement to create a tuple with three items.
● What is list comprehension?
● How do you access values in a dictionary?
Sixteen Mark Questions:
11. Explain the operations of lists with illustrative examples.
12. Compare and contrast tuples and lists in Python.
13. Discuss dictionary operations with examples.
14. Write a program to prepare a retail bill using dictionary.
15. Explain list comprehension with multiple examples.
UNIT IV – FILES, MODULES, PACKAGES
Two Mark Questions:
● How do you open a file in Python?
● What is the use of `read()` and `write()` methods?
● Define module.
● What is the purpose of the `import` keyword?
● How are exceptions handled in file operations?
● Write a statement to read all lines of a text file.
● Define package in Python.
● What is the use of commandline arguments?
● How do you handle file not found errors?
● Mention any two file modes in Python.
Sixteen Mark Questions:
16. Explain reading and writing operations on text files in Python.
17. Write a program to count the number of words in a file.
18. Discuss how to handle errors and exceptions during file operations.
19. Explain modules and packages in Python with examples.
20. Write a program for marks range validation (0100) using file input.
UNIT V – EXCEPTIONS, LIBRARIES
Two Mark Questions:
● What is an exception?
● Write the syntax of try except block.
● Define built in exceptions with examples.
● Mention any two built in exceptions.
● What is the purpose of `finally` block?
● How do you raise a custom exception?
● Name two Python standard libraries.
● What is the use of `assert` statement?
● Define an Integrated Development Environment (IDE).
● What is the difference between `try except` and `try finally`?
Sixteen Mark Questions:
21. Explain exception handling mechanism in Python.
22. Write a program to handle multiple exceptions using try except.
23. Discuss application development using Python IDE.
24. Write a program to validate voter’s age using exceptions.
25. Explain the use of Python standard libraries in application development.