Computer Programming
Computer Programming
Question Bank
B.
Marks CO’s
L
PART A (2 Mark)
UNIT I
1 Describe the role of the print function in Python. 2 K2 CO1
How can a string be represented in a program? Provide an example. CO1
2 2 K1
When is a variable created in Python? CO1
3 2 K1
What does the `input()` function return in Python? CO1
4 2 K1
5 What will be the output of the following code: `a = "5.0"; a = int(a)`? 2 K1 CO1
6 What will be the output of the code `print(12 == 12.0)` ? 2 K1 CO1
Explain how the logical OR operator works with the example `(3 > 1) or
7 2 K2 CO1
(1 > 3)`.
What is the difference between printing a numerical operation and a
8 2 K2 CO1
string in Python?
9 Explain the difference between a variable and a value with an example. 2 K2 CO1
What is the output of the following Python code: `print("age")` if `age`
10 2 K1 CO1
has been assigned a value?
UNIT II
1 What is the purpose of the `range(n)` function in Python? 2 K1 CO2
2 Why is it necessary to update the counter variable inside a while loop? 2 K1 CO2
3 What is a nested loop in programming? 2 K1 CO2
How does Python handle variable names that are the same inside and
4 2 K1 CO2
outside a function?
5 What is a nested conditional block in programming? 2 K1 CO2
6 What is the purpose of the function call stack? 2 K1 CO2
7 What is the purpose of the `print()` function in Python? 2 K1 CO2
Describe how the modulus operator can help in finding the last digit of a
8 2 K2 CO2
number.
Evaluate the impact of using the `return` statement in a function, with
reference to the given examples.
def greet(word):
9 msg = "Hello " + word
2 K5 CO2
return msg
print("This will not run")
result = greet("Teja")
print(result)
What happens if there is inconsistent indentation within a conditional
10 2 K2 CO2
block in Python?
UNIT III
What happens if you try to create a set with duplicate items in Python?
1 2 K1 CO3
How can you sort the list [4, 1, 3] in ascending order using the sort()
2 2 K3 CO3
method?
3 What does accessing a nested list mean, and how is it done in Python? 2 K2 CO3
How does the `issuperset()` method function, and what would be its
4 2 K1 CO3
result for the sets {4, 6} and {2, 6}?
What error does Python raise when attempting to unpack a tuple into a
5 2 K3 CO3
mismatched number of variables, and why does this error occur?
6 What is a set in Python, and what are its key characteristics? 2 K2 CO3
How would you find the index of the number 4 in the list [7, 4, 6, 4] using
7 2 K3 CO3
the index() method?
Demonstrate how to name placeholders in a string format method to
8 display "Alice is 30 years old" using `name = "Alice"` and `age = 30`.
2 K3 CO3
Given two sets, `set_x = {3, 6, 9}` and `set_y = {6, 12, 15}`, how would
9 2 K3 CO3
you find the union of these sets in Python?
10 How is a tuple created in Python? Provide an example. 2 K1 CO3
UNIT IV
What is the output when updating a class attribute in one instance of a
1 2 K2 CO4
class, and why?
How does the addition operator demonstrate polymorphism with
2 2 K1 CO4
different data types in Python?
Explain the error received when trying to print an instance attribute
3 2 K2 CO4
without using 'self' in a method.
4 What is polymorphism in the context of programming? 2 K1 CO4
How are instance attributes different from class attributes in Python
5 2 K1 CO4
classes?
How does method overriding demonstrate polymorphism in subclasses
6 2 K3 CO4
of a given class in Python?
Describe how a NameError could occur when accessing instance
7 2 K1 CO4
attributes in Python.
Why does Python not support method overloading by default, and what
8 happens when attempts are made to overload methods?
2 K1 CO4
What happens if you try to access an instance attribute using the class
9 2 K1 CO4
name instead of an object?
Explain the difference between inheritance and composition in object-
10 2 K1 CO4
oriented programming.
UNIT V
1 What is a module in the context of Python's Standard Library? 2 K1 CO5
2 What are exceptions in Python? 2 K1 CO5
3 Explain the role of the `timedelta` class in the `datetime` module. 2 K2 CO5
4 Explain what a namespace is and its importance in Python. 2 K2 CO5
Explain how the `reduce()` function is used in Python and mention the
5 2 K1 CO5
module it belongs to.
6 What are syntax errors in Python? 2 K1 CO5
What is a valid format for representing a `time` object in Python? Provide
7 2 K1 CO5
an example.
8 What role does the scope of a name play in a Python program? 2 K2 CO5
9 What does aliasing a module mean in Python, and how is it done? 2 K1 CO5
10 How does raising exceptions help in developing reusable modules? 2 K2 CO5
UNIT III
How would you use the `append()` method to add multiple 10
1 K3 CO3
elements to a list in a loop?
Describe how the `extend()` method can be used to combine two
2 10 K3 CO3
lists and provide an example.
Demonstrate how you can use the `insert()` method to place an
3 10 K3 CO3
element at a specific position in a list.
How can you use a tuple to store multiple data types in a single
4 10 K3 CO3
variable in Python? Provide an example.
Illustrate how to perform membership checks in tuples using
5 10 K3 CO3
Python. Provide two different scenarios with examples.
Describe the process of tuple packing in Python with an
6 10 K3 CO3
example. Explain how it differs from tuple unpacking.
Given the set `set_b = {"apple", "banana", "cherry"}`, show how
7 to add the elements of the list `["date", "fig", "apple"]` to this set. 10 K3 CO3
What will the final set look like?
Convert the string "banana" to a set and explain the resulting
8 10 K3 CO3
set's characteristics, focusing on order and uniqueness.
Design a Python function that takes two sets as input and
9 returns their union, using both the union operator and the union() 10 K6 CO3
method. Compare the results to ensure they are identical.
Given the list `list_a = ["Five", "Six"]`, write a code to access the
10 10 K3 CO3
letter `i` from the word `Five`.
UNIT IV
How can encapsulation be implemented in a Python class to
ensure that an object's attributes and methods are bundled 10
1 K3 CO4
together into a single entity? Provide a code example to illustrate
your explanation.
Design a class hierarchy for an e-commerce site that includes a
new product category, "Furniture", using the principles of
inheritance. Ensure that the "Furniture" class inherits common
2 10 K6 CO4
attributes and methods from a base class and includes additional
specific attributes relevant to furniture items. Provide a code
example demonstrating this hierarchy.
Develop a multilevel inheritance structure that includes a base
class `Product`, a subclass `ElectronicItem`, and a further
3 subclass `Smartphone`. Implement a method in `Smartphone` to 10 K6 CO4
display additional smartphone features such as OS and storage
capacity.
Explain how different classes can have methods with the same
4 name and how this represents class polymorphism in Python. 10 K3 CO4
Provide an example.
Compare and contrast method overloading and method overriding,
5 10 K5 CO4
focusing on their implications for code flexibility and extensibility.
How would you implement a basic shopping cart system with
6 functionality to add items and check out, considering both regular 10 K4 CO4
and offer sales conditions using class and instance attributes?
Critically assess the impact of operator overloading on
7 10 K5 CO4
programming efficiency and error reduction, using examples.
Create a class method for a cart system that updates the
minimum bill requirement dynamically based on a given
8 percentage increase during different sales seasons. Explain 10 K6 CO4
how this method impacts the checkout process.
UNIT V
Illustrate how to use the `filter()` function to extract even 10
1 K3 CO5
numbers from a list.
Create a scenario using a function where a local variable and a
2 global variable have the same name. Explain their scope and the 10 K3 CO5
expected outcome when the function is executed.
Analyze the role of the `raise` keyword in Python's exception
3 10 K4 CO5
handling, and discuss its usage with practical examples.
How can you calculate the exact date and time 500 hours from
4 10 K3 CO5
now using Python's `datetime` module?
Create a Python program that uses global variables and
demonstrates the effect of modifying these variables inside a
5 function using the `global` keyword. Provide explanations within 10 K6 CO5
your code.
Evaluate the challenges and limitations of using the `date` class
6 in Python's `datetime` module, especially concerning error 10 K5 CO5
handling and input validation.
Evaluate the effects of using Python's `map()`, `filter()`, and
7 `reduce()` functions on the overall design and performance of 10 K4 CO5
Python programs.
Explain how to import and use a specific function from a
8 Python module with an alias, using the math module as an 10 K3 CO5
example.
Write a Python script using the `map()` function to convert a
9 list of string numbers into integers and then double each 10 K6 CO5
integer.
Describe how the filter function works and provide an
10 example that filters out negative numbers from a list. 10 K5 CO5
UNIT III
Develop a Python program that demonstrates the difference
between the `sort()` method and the `sorted()` function. Your 10
1 K6 CO3
program should include examples of both and explain the impact
on the original list.
Analyze how nested lists function in Python and explain how
2 elements within a nested list can be accessed, using the given 10 K4 CO3
examples. list_a = [5, "Six", [8, 6], 8.2]
Construct a Python function that uses default arguments to simulate a
3 simple calculator. Demonstrate multiple calculations, explaining the 10 K6 CO3
impact of default arguments on the results
UNIT IV
Evaluate the impact of setting different minimum cart values
during regular sales and offer sales on the overall shopping 10
1 K5 CO4
experience. Consider how these values influence user behavior
and business outcomes.
Evaluate the process of organizing object descriptions in OOP and
2 its effect on software clarity and functionality. 10 K4 CO4