0% found this document useful (0 votes)
3 views8 pages

Computer Programming

Uploaded by

ece3sharif50
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Computer Programming

Uploaded by

ece3sharif50
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SCHOOL OF COMPUTATIONAL ENGNINEERING

Question Bank

Degree & Branch:


Course Code: Semester:
Course Name:

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

PART B (10 Mark)


UNIT I
Design a Python program that demonstrates the use of variables
to store and manipulate different data types, including String, 10
1 K4 CO1
Integer, Float, and Boolean. Explain the purpose of each
variable in your program.
Construct a Python script that initializes four variables with
different data types and performs a type check to print the data
2 10 K4 CO1
type of each variable. Include comments to explain each step of
the script.
Evaluate the process and importance of sequence of execution
3 in a Python program through the example of uninitialized 10 K4 CO1
variable usage.
Evaluate the importance of understanding string concatenation
4 in Python programming. Discuss potential errors that could arise 10 K5 CO1
from improper use.
Given a string "Welcome to Python Programming", write a
5 Python code to slice and obtain the substring "Python" using 10 K3 CO1
string slicing.
Evaluate the implications of string comparison using relational
6 operators in Python, with a focus on case sensitivity and data 10 K5 CO1
type considerations.
Analyze the outcome of the following expression using logical
7 operators: `(True or False) and not(False and True)`. Explain the 10 K4 CO1
step-by-step evaluation process.
Evaluate the importance of indentation in Python conditional
8 10 K5 CO1
statements and its impact on code execution.
Develop an algorithm using the modulus operator to determine if
9 10 K6 CO1
a number is odd or even, and explain its working with examples.
Develop a Python snippet that calculates and prints the result of the
10 expression `10 / 2 + 3` and `10 / (2 + 3)`. Explain the difference in the 10 K6 CO1
results.
UNIT II
Compare how the condition in a while loop affects the execution 10
1 K4 CO2
flow versus a fixed iteration structure like a for loop.
How do you implement the logic to print the second line of a 7x7
2 10 K3 CO2
hollow right-angled triangle pattern?
Analyze the role of `capitalize()`, `title()`, and `swapcase()`
3 methods in transforming the string "hello WORLD". Provide code 10 K4 CO2
examples for each transformation.
Evaluate the role of `find()` and `rfind()` methods in handling
4 string searches and their advantages over `index()` and 10 K5 CO2
`rindex()`. Provide examples.
Apply the concept of a while loop inside a for loop to print
5 10 K3 CO2
numbers from 1 to 3 three times.
Evaluate the effectiveness of using compound assignment
operators such as `+=`, `-=`, `*=`, `/=`, and `%=`, in terms of
6 10 K5 CO2
code readability and performance. Provide examples to support
your evaluation.
Evaluate the importance of the `ord()` and `chr()` functions in
7 10 K4 CO2
Python string operations.
If you have a list `list_a = [1, 2]`, how can you concatenate it with
8 another list `list_b = ["a", "b"]` and what will the resulting list look 10 K3 CO2
like?
How can you determine the identity of an object in Python using
9 the `id()` function? Provide a practical example involving a string 10 K3 CO2
object.
How do you handle out-of-bounds indices when slicing a list in
10 10 K3 CO2
Python?

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.

Apply the concept of function polymorphism using the


9 'len()' function in Python to find the length of different data 10 K3 CO4
types.
Develop a Python script that uses method overloading by
function default arguments and demonstrates
10 polymorphism in calculating the area of different shapes 10 K6 CO4
(e.g., circle, rectangle). Provide a detailed explanation of how
method overloading is achieved in Python.

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

PART C (10 Marks) (Case study)


UNIT I
Discuss how Python handles string concatenation when using
10
1 variables to store strings, and provide an example to demonstrate K2 CO1
variable-based concatenation.
Analyze the expression `not((5 > 3) and (2 < 1))` and explain the
2 logical operations step-by-step to determine the result. 10 K4 CO1

Evaluate the potential consequences of syntax errors when using


3 relational operators in Python, and discuss how these errors can 10 K5 CO1
impact the execution of a program.
UNIT II
Analyze how nested conditional blocks can be used to implement
10
1 decision trees in Python. Discuss the strengths and limitations of K5 CO2
this approach with examples.
Create a program using the modulus operator to determine if a
2 number is odd or even, and explain its working with examples. 10 K6 CO2

Analyze how nested conditional blocks can be used to implement


3
decision trees in Python. Discuss the strengths and limitations of 10 K5 CO2
this approach with examples.

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

Analyze the importance of modeling software after real-life objects in


3 Object-Oriented Programming (OOP) and its impact on software 10 K4 CO4
design.
UNIT V
Write a program using `filter()` in Python for data processing tasks, 10
1 K5 CO5
compared to conventional list comprehensions or loops.
Design a Python program using the `date` class that calculates the
number of days left until a specified future event date. The program
2 should take input from the user for the event date in the format 'YYYY- 10 K6 CO5
MM-DD' and output the number of days left until that event. Explain
the key components and logic used in your program.
Implement a Python function to safely divide two numbers, ensuring
3 that both input values are integers and handling any exceptions that may 10 K3 CO5
occur.

Industry Trainer School Incharge

You might also like