0% found this document useful (0 votes)
363 views4 pages

Python Exam Questions for B.Tech CSE

Uploaded by

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

Python Exam Questions for B.Tech CSE

Uploaded by

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

Set – 1

End Semester Examination, Dec 2025


[Link]. – CSE, 3rd Semester
Course Code: 5.0CE202E02H (Python)
Time: 3 Hrs | Max Marks: 80

Q.1 [CO1–CO4 | BTL 1–3 | 2×10 = 20 Marks]


Answer all:
a) Define mutable and immutable data types in Python with one example each. [CO1 |
BTL1]
b) Differentiate between while and for loops. [CO1 | BTL2]
c) Write a Python expression to compute the cube of a number without using **. [CO1 |
BTL3]
d) List two differences between tuple and list. [CO2 | BTL2]
e) Write Python code to add two sets {1,2,3} and {3,4,5}. [CO2 | BTL3]
f) Define recursion with a simple factorial function example. [CO3 | BTL2]
g) What is method overloading? Can it be achieved directly in Python? [CO3 | BTL2]
h) Write a simple Python class Student with attributes name and roll_no. [CO3 | BTL3]
i) State one advantage of using NumPy arrays over Python lists. [CO4 | BTL2]
j) Mention two Python libraries used for image processing. [CO4 | BTL1]

Q.2 [CO1 | BTL 2–4 | 15 Marks]


(a) Explain different data types in Python with suitable examples. [CO1 | BTL2] (7.5)
(b) Write a Python program to display Fibonacci series up to n terms using a loop. [CO1 |
BTL3/4] (7.5)

Q.3 [CO2, CO3 | BTL 3–5 | 15 Marks]


(a) Write a function in Python that accepts a list of numbers and returns the second
largest element. [CO2 | BTL3/4] (7.5)
(b) Define inheritance. Write Python code to demonstrate multilevel inheritance with
Person → Student → ResearchScholar. [CO3 | BTL4/5] (7.5)

Q.4 [CO4 | BTL 3–5 | 15 Marks | Unit 5]


(a) Write Python code using NumPy to create a 3×3 identity matrix and compute its
transpose. [CO4 | BTL3/4] (7.5)
(b) Create a Pandas DataFrame of 5 students with columns Name, Age, Marks. Write
code to:
- Display students with Marks > 70
- Compute average marks
[CO4 | BTL4/5] (7.5)

Q.5 [CO4 | BTL 2–5 | 15 Marks | Unit 6]


(a) Explain any three image-processing functions from PIL with code examples. [CO4 |
BTL2/3] (7.5)
(b) Write Python code using Matplotlib to plot a bar chart of student names vs marks.
[CO4 | BTL4/5] (7.5)
Set – 2
End Semester Examination, Dec 2025
[Link]. – CSE, 3rd Semester
Course Code: 5.0CE202E02H (Python)
Time: 3 Hrs | Max Marks: 80

Q.1 [CO1–CO4 | BTL 1–3 | 2×10 = 20 Marks]


Answer all:
a) What is the difference between is and == operators? [CO1 | BTL2]
b) Write Python code to reverse a string "HELLO". [CO1 | BTL3]
c) Define list slicing with an example. [CO2 | BTL2]
d) Write a program to count frequency of elements in a tuple. [CO2 | BTL3]
e) Differentiate between remove() and pop() in lists. [CO2 | BTL2]
f) Write a recursive function to calculate the sum of first n natural numbers. [CO3 |
BTL3]
g) Define constructor in Python. Give an example. [CO3 | BTL2]
h) Create a class Circle with methods to compute area and circumference. [CO3 | BTL3]
i) What is broadcasting in NumPy? [CO4 | BTL2]
j) Mention two differences between OpenCV and PIL. [CO4 | BTL1]

Q.2 [CO1 | BTL 2–4 | 15 Marks]


(a) Explain different control statements in Python with examples. [CO1 | BTL2] (7.5)
(b) Write Python code to check whether a number is prime or not. [CO1 | BTL3/4] (7.5)

Q.3 [CO2, CO3 | BTL 3–5 | 15 Marks]


(a) Write a program to merge two dictionaries and remove duplicate keys. [CO2 |
BTL3/4] (7.5)
(b) Explain types of inheritance in Python with code examples. [CO3 | BTL4/5] (7.5)

Q.4 [CO4 | BTL 3–5 | 15 Marks | Unit 5]


(a) Using NumPy, create a 2D array of shape (4,4). Perform slicing to extract a 2×2 sub-
matrix. [CO4 | BTL3/4] (7.5)
(b) Write Python code to read data from a CSV file into Pandas and display only the first
5 rows. [CO4 | BTL4/5] (7.5)

Q.5 [CO4 | BTL 2–5 | 15 Marks | Unit 6]


(a) Write short notes on scaling, rotating, and converting an image to grayscale using
Python libraries. [CO4 | BTL2/3] (7.5)
(b) Write Python code using Matplotlib to plot a line chart for monthly sales (Jan–June).
[CO4 | BTL4/5] (7.5)

Common questions

Powered by AI

Python does not support method overloading like some other languages because it allows functions to be defined with the same name but with dynamic argument handling. Instead, it uses default arguments or *args to handle different numbers or types of inputs. This flexibility reduces redundancy but requires careful implementation to avoid runtime errors due to incorrect argument handling, influencing how developers design functions for robustness and versatility .

Mutable data types in Python, such as lists and dictionaries, allow modification of their content without changing their identity. For example, a list [1, 2, 3] can have its elements changed, appended, or removed. Immutable data types, on the other hand, like tuples and strings, cannot be altered once created. Any change would involve creating a new object. For instance, any modification to a tuple would require creating a new tuple object .

To create a Circle class in Python, define a constructor (__init__) that initializes the radius attribute. Then, implement methods to calculate the area (using πr²) and the circumference (using 2πr). Encapsulation is important here for maintaining the integrity of the circle's data, allowing manipulation through defined interfaces, and protecting internal state from unintended external modifications, enhancing code reliability and reusability .

NumPy arrays are more efficient than Python lists because they store elements in contiguous blocks of memory, allowing faster computations through vectorized operations with optimized C/Fortran libraries, reducing loop overhead. This efficiency is crucial for large-scale data analysis tasks, enabling faster processing and the application of mathematical operations on entire arrays without explicit loops, greatly enhancing performance in scientific computing and data manipulation tasks .

The PIL library offers functions like 'resize()' to alter image dimensions, 'rotate()' to change orientation, and 'convert()' to modify image modes (e.g., color to grayscale). These functions enable flexible and straightforward image manipulations, essential for preparing images for further analysis or visualization, enhancing their usability in automated image-processing pipelines .

OpenCV is a more comprehensive and efficient library for image processing, supporting real-time operations and a wide array of features including computer vision algorithms. PIL (or its successor Pillow) is simpler, providing basic image processing capabilities like opening, manipulating, and saving image files. OpenCV is suited for demanding applications like motion detection, whereas PIL is adequate for basic tasks like image format conversions .

The 'remove()' function in Python's lists deletes the first occurrence of a specified value, e.g., in [1, 2, 3], lst.remove(2) removes 2. 'Pop()' removes an item at a specified index and returns it, e.g., in [1, 2, 3], lst.pop(1) removes and returns 2. 'Remove()' is used when the value is known, while 'pop()' is useful when direct index access is needed .

'While' loops in Python are condition-based, repeatedly executing a block of code as long as a condition remains true, suitable for scenarios where the number of iterations isn't known upfront. 'For' loops iterate over items of a sequence (like lists or strings), ideal when the number of iterations is predetermined. This makes 'for' loops generally cleaner and more predictable for iterating over sequences, while 'while' loops offer more flexibility for conditions that might vary .

Pandas DataFrames offer tabular data representation with labeled axes, providing powerful data manipulation and analysis capabilities. For example, creating a DataFrame for students with columns Name, Age, Marks allows operations like filtering students with Marks > 70 and computing average marks seamlessly using built-in functions. This structure facilitates complex data transformations and insights extraction through intuitive syntax .

Broadcasting in NumPy allows arithmetic operations between arrays of different shapes by 'stretching' the smaller array across the larger one without copying data. This enables concise and efficient computation, allowing operations like adding a scalar to a matrix without explicit loops. It simplifies code and improves computational performance, crucial for large-scale scientific computations .

You might also like