0% found this document useful (0 votes)
100 views2 pages

Python Programming Question Paper 2023

The document is an examination paper for a Python Programming course at Maulana Abul Kalam Azad University of Technology, West Bengal. It includes various types of questions such as very short answer type, short answer type, and long answer type, covering topics like Python syntax, functions, inheritance, and data structures. The paper is structured to assess students' understanding and application of Python programming concepts within a 3-hour timeframe for a total of 70 marks.

Uploaded by

Mouboni Ghosh
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)
100 views2 pages

Python Programming Question Paper 2023

The document is an examination paper for a Python Programming course at Maulana Abul Kalam Azad University of Technology, West Bengal. It includes various types of questions such as very short answer type, short answer type, and long answer type, covering topics like Python syntax, functions, inheritance, and data structures. The paper is structured to assess students' understanding and application of Python programming concepts within a 3-hour timeframe for a total of 70 marks.

Uploaded by

Mouboni Ghosh
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

CS/BCA(A)/E\:'EN/SEM-4/400088/2023-2024/1108

-·---·---.,.

~
MAULANA ABUL KAIAM AZAD UNIVERSITY OF TECHNOLOGY, WEST BENGAL
Paper Code: BCACA03 Python Programming
UPID: 400088

Time Allotted : 3 Hours Full Marks : 70


The Figures in the margin Indicate full marks.
Candidate are required to give their answers in the/r own words as far as practicable

I 1. Answer any ten of the following :


l•l
Group-A (Very Short Answer Type Question)

What will be the output of the following Python code?


( 1 X 10 = 10]

»> a={5, 4}

))) b={l,2,4,5}

»> a(b
<111 What is the extension of the Python file?
(Ill) What will be the output of the following Python program?

i =0

while i < 5:
print(i)
i += 1
if i == 3:
break
else:
!
i
I print(0)
!
/
jlVl Suppose listl is [2, 33, 222, 14, 25], What is listl[:-1]?
(¥( What will be the output of the,following Python code?

)))my_tuple = (1, 2, 3, 4)
)))my_tuple.append( (5, 6, 7))
.)))print len{my_tuple)
(Vil

(VII)
What will be the value of the following Python expression?
4+3%5
What will be the output of the following PythoH code?
(
print("Hello {0(0]} and {0(1]}".format(('foo', 'bin')))
(Y111l What will be the output of the following Python code?

a=[ 13, 56, 17]


[Link]([87])
[Link]([45,67])
print(a)

(i{i What will be the output of the following Python code?

~
1/2

II.
~ ~ - -......... ....,
(~;
,0

/
/
~ >» a=~,s,s)
>» b=(2, 8, ~
>» ~ ~•"--\:(~+ceb')
In python?
(Xl What is. the order of preceden
......
(XI) The process of pickling
in Python Includes _ _ __
following Python code?
1xnf What will be the output of the

>>>t = (1, 2, 4, 3, 8, 9)
2)]
»> [t[i ] for i in range(0, len( t),
stion)
Group-B (Short Answer Type Que { 5 X 3 = 15)
Answer any three of the following :
{5)
the same value for every class instance (object).
2. Define a property that must have [SJ
3. Define variable in Python? {SJ
4. Is elif a nested if in Python? (SJ
5. What are functions in Python? [SJ
nct integers.
ible unique subsets from a set of disti
6. Write a Python class to get all poss
)
Group-C (Long Answer Type Question [ 15 X 3 = 45]
Answer any three of the following :
[ 5]
7. (a) Define functions in Python. [ 10 J
ks whether the number i_s
a number as a parameter and chec
(b) Write a Python function that takes
prime or not. [ 10 J
Python?
disadvantages of using a for loop in
.8. (a) What are the advantages and [ 5]
t in a for loop in Pyth on?
{b) How can I use a break statemen [ 10]
on with an example.
'9. (a) Explain Inheritance in Pyth f5]
on?
{b) How are classes created in Pyth [ 15 J
name and student_class from
e a Python func tion student_data () that will take as argument student_
10. Writ
and class.
the user and print the student name [5J
in Python?
11. (a) How to comment multiple lines [ 10]
Explain with an example.
(b) What is a dictionary in Python?

**• END OF PAPER •••

2/2

Common questions

Powered by AI

Pickling in Python refers to the process of converting a Python object into a byte stream, enabling the object to be saved to a file or transferred over a network. Unpickling is the inverse process where a byte stream is converted back into a Python object. This is significant for persisting complex data types like objects or dictionaries across sessions or for distributed systems where objects need to be transmitted between nodes. However, care must be taken as pickled data can be maliciously crafted to execute arbitrary code; therefore, unpickling data from untrusted sources poses significant security risks.

The 'break' statement in Python is used within loops to exit the loop prematurely when a specified condition is met, effectively allowing for greater control over the flow of a program. Practically, this can optimize performance by avoiding unnecessary iterations once a desired outcome is achieved, such as finding the first occurrence of a target value in a list. While 'break' provides control, it can lead to less readable code as it introduces hidden exits from loops, complicating the understanding of loop behavior, especially in deeply nested or concurrent loops. Using 'break' judiciously is recommended, to enhance looping logic without compromising code clarity.

Variable scope in Python refers to the accessibility of a variable in different parts of the code, crucial in ensuring that variables are used correctly and predictably. Python has four scopes: local, enclosing, global, and built-in (LEGB rule). Local scope refers to variables defined within a function, accessible only within that function, which helps avoid variable pollution or unwanted side-effects across different functions. Enclosing scope pertains to functions enclosed within other functions, allowing nested functions to access parent variables. Global scope allows variables defined outside any function to be accessed globally within the module. Understanding and correctly applying scopes prevents accidental modifications of variables, reduces the risk of bugs related to unpredictable variable states, and enhances the maintainability of the code.

In Python, a class encapsulates attributes (data) and methods (functions) that define the behavior. This encapsulation allows for the modeling of real-world entities or abstract ideas with attributes representing properties and methods executing behaviors. For example, a 'Dog' class might encapsulate attributes like 'breed' and 'age', and methods like 'bark()' or 'fetch()'. This class structure enhances data and function organization, promotes reuse and abstraction, and prevents unauthorized access to sensitive data by controlling access through methods. Encapsulation also aids in maintaining the integrity of an object's state by ensuring proper initialization and data validation through class invariants.

"For loops" in Python offer the advantage of iterating over items in a collection (like a list or tuple) directly, which can make the code more concise and readable. They inherently handle the iteration over sequences without needing to manage indices explicitly. However, they are limited by the fact that they cannot be used to dynamically modify the list they are iterating over, as altering the list size during iteration can lead to skipped elements or runtime errors. Additionally, they lack the fine control that a "while loop" might offer, such as precise control over when the loop should behave in non-standard ways (e.g., skipping items)

A Python dictionary is a collection of key-value pairs, where each key is unique and must be immutable (such as strings or tuples). It is defined using curly braces with pairs separated by colons, like {key1: value1, key2: value2}. Dictionaries are highly efficient for lookups, insertions, and deletions. They are used in scenarios where the association between keys and values is necessary, such as representing structured data, counting frequencies of items, or implementing caches. Dictionary keys can be used to quickly access associated values, making them ideal for use cases like configuration management or data storage in flexible formats.

In Python, to ensure that a property holds the same value for every instance of a class, one can use class variables. A class variable is defined inside a class but outside any instance methods, and it is shared across all instances. This is important for maintaining consistency across instances when some data or configuration is meant to be universal for the class. For instance, a class 'Book' could have a class variable 'library_branch' if all books in the system are associated with the same branch. Accessing or modifying a class variable through instances affect all instances, reflecting the shared nature of the variable. It becomes crucial in scenarios where uniform configuration is necessary across different instances, ensuring cohesion in behaviors and attributes.

A Python set is initialized using either a set literal, such as `{}` or the `set()` constructor. For example, `my_set = {1, 2, 3}` or `my_set = set([1, 2, 3])`. Sets, which are unordered collections of unique elements, provide methods for common operations like `add()` to insert items, `remove()` or `discard()` to delete items, `union()` or `update()` for combining sets, and `intersection()` for finding common elements between sets. Such operations enable efficient data handling, especially useful in scenarios dealing with unique data entries or requiring mathematical set operations like union, intersection, and differentiation.

Functions in Python are blocks of reusable code that perform a specific task, defined using the "def" keyword. They allow for code modularity and abstraction, making programs easier to write, debug, and understand. Functions facilitate code reuse, which improves efficiency by reducing redundancy. Additionally, functions can take arguments to accept data, process it, and return results using the "return" statement, further enhancing flexibility in code design. By encapsulating tasks, functions help maintain clean and organized code, crucial in larger projects for maintaining readability and manageability.

In Python, classes serve as blueprints for creating objects (instances), encapsulating data for the object and functions that manipulate that data, thus implementing the principles of object-oriented programming (OOP). Classes promote code reusability and modularity. Inheritance allows a class (derived class) to inherit attributes and methods from another class (base class), facilitating code reuse and the creation of hierarchical class structures. For example, a "Vehicle" class may have a derived class "Car" which inherits the basic attributes of a "Vehicle" but also includes additional attributes or behaviors specific to cars. This mechanism enables polymorphism and abstraction, which are key OOP concepts.

You might also like