AKTU Python Programming Question Paper 2025
B.Tech III Semester – BCC302 – Python Programming
This page provides the AKTU B.Tech Python Programming Question Paper 2024–25 for BCC302 along with complete exam-oriented solutions.
Question Paper – Section Wise
| Section | Question | Marks |
|---|---|---|
| Section A | Q1 – Attempt all questions in brief | 02 × 7 = 14 |
| Section B | Q2 – Attempt any three | 07 × 3 = 21 |
| Section C | Q3 – Q7 – Attempt any one from each question | 07 × 5 = 35 |
Section A – Short Answer Questions
Q1. Attempt all questions in brief.
Q1(a)
Question: State how to handle exceptions in Python? Provide a simple example.
Q1(b)
Question: What will be the output of the following Python program?
def compute(x):
return [i**2 for i in x if i%2==0]
print(compute([1, 2, 3, 4, 5]))
Q1(c)
Question: Explain floor division with an example.
Q1(d)
Question: Describe the purpose of the with statement in file handling.
Q1(e)
Question: Briefly describe the use of lambda functions in Python.
Q1(f)
Question: Demonstrate how to assign a single value to a tuple.
Q1(g)
Question: Explain why NumPy is used instead of Python arrays for mathematical calculations.
Section A – Answers
Q1(a) Answer
Exceptions in Python are handled using the try, except, else and finally blocks. The try block contains the code that may generate an exception, while the except block handles the exception.
try:
a = 10
b = 0
print(a / b)
except ZeroDivisionError:
print("Cannot divide by zero")
Output:
Q1(b) Answer
The list comprehension selects only even numbers from the list and calculates their squares.
[4, 16]
Q1(c) Answer
Floor division is performed using the // operator. It returns the quotient after rounding down to the nearest integer.
print(10 // 3)
Output: 3
Q1(d) Answer
The with statement is used to handle files safely. It automatically closes the file after the operation is completed, even if an exception occurs.
with open("data.txt", "r") as file:
data = file.read()
print(data)
Q1(e) Answer
A lambda function is a small anonymous function defined using the lambda keyword. It can take any number of arguments but contains only one expression.
square = lambda x: x * x
print(square(5))
Output: 25
Q1(f) Answer
A single-value tuple is created by placing a comma after the value. The comma is necessary to identify it as a tuple.
t = (10,)
print(t)
Output: (10,)
Q1(g) Answer
NumPy is preferred for mathematical calculations because it provides efficient numerical arrays and supports fast mathematical operations. It also provides many functions for scientific and numerical computing.
NumPy arrays generally require less memory and perform numerical operations faster than ordinary Python lists.
Section B – Answers
Q2. Attempt any three of the following.
07 × 3 = 21
Q2(a) Answer
Question: Design a basic calculator in Python that supports addition, subtraction, multiplication and division.
A calculator can be implemented using arithmetic operators and conditional statements.
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
choice = int(input("Enter your choice: "))
if choice == 1:
print("Result =", a + b)
elif choice == 2:
print("Result =", a - b)
elif choice == 3:
print("Result =", a * b)
elif choice == 4:
if b != 0:
print("Result =", a / b)
else:
print("Division by zero is not possible")
else:
print("Invalid choice")
Q2(b) Answer
Question:
Define Membership and Identity Operators. Given:
a = 3, b = 3, distinguish between
(a is b) and (a == b).
Membership operators are used to check whether a value is present in a sequence. The membership operators are in and not in.
Identity operators are used to check whether two variables refer to the same object. The identity operators are is and is not.
a = 3
b = 3
print(a == b)
print(a is b)
Difference:
| Operator | Purpose |
|---|---|
== |
Checks whether the values of two objects are equal. |
is |
Checks whether two variables refer to the same object. |
For the given small integer values, Python commonly reuses integer
objects, so both expressions may produce True.
However, == checks value equality, whereas is
checks object identity.
Q2(c) Answer
Question: Write a Python function to count the frequency of each character in a given string and return the output in a dictionary.
Example:
char_frequency("HELLO") returns
{"H":1, "E":1, "L":2, "O":1}.
def char_frequency(text):
frequency = {}
for ch in text:
if ch in frequency:
frequency[ch] += 1
else:
frequency[ch] = 1
return frequency
result = char_frequency("HELLO")
print(result)
Output:
Q2(d) Answer
Question: Write a program to reverse the contents of a file character by character, separating each character with a comma.
with open("data.txt", "r") as file:
content = file.read()
reversed_content = content[::-1]
result = ",".join(reversed_content)
with open("output.txt", "w") as file:
file.write(result)
print(result)
The program reads the complete contents of the file, reverses the
characters using slicing and separates every character using a comma.
The final result is stored in output.txt.
Q2(e) Answer
Question: Create a pie chart using Matplotlib to represent the following data:
| Language | Value |
|---|---|
| Python | 30 |
| Java | 25 |
| C++ | 20 |
| JavaScript | 15 |
| Ruby | 10 |
import matplotlib.pyplot as plt
languages = ["Python", "Java", "C++", "JavaScript", "Ruby"]
values = [30, 25, 20, 15, 10]
plt.pie(values, labels=languages, autopct="%1.1f%%")
plt.title("Programming Languages")
plt.show()
The pie() function is used to create the pie chart.
The labels parameter displays the language names and
autopct displays the percentage values.
Section C – Answers
Q3(a) Answer
Question: Write short notes on Operator Precedence, Python Indentation and Type Conversion.
1. Operator Precedence:
Operator precedence determines the order in which operators are
evaluated in an expression. Operators with higher precedence are
evaluated before operators with lower precedence.
result = 10 + 5 * 2
print(result)
Output: 20
Multiplication is performed before addition. Parentheses can be used to change the order of evaluation.
2. Python Indentation:
Indentation is used to define blocks of code in Python. Unlike many
other programming languages, Python does not use braces
{ } to define blocks.
if 10 > 5:
print("10 is greater than 5")
The indented statement belongs to the if block.
Incorrect indentation results in an error.
3. Type Conversion:
Type conversion means converting a value from one data type to
another. Python provides functions such as int(),
float(), str() and bool()
for type conversion.
x = "25"
a = int(x)
b = float(x)
print(a)
print(b)
Q3(b) Answer
Question:
Write a program to validate email addresses using regular expressions.
The email must contain @, must contain a domain name and
should not contain spaces.
Regular expressions are used to search and validate patterns in text.
Python provides the re module for working with regular
expressions.
import re
email = input("Enter email address: ")
pattern = r"^[^@\s]+@[^@\s]+\.[^@\s]+$"
if re.match(pattern, email):
print("Valid email address")
else:
print("Invalid email address")
The regular expression checks that the email contains an
@, has a domain part and does not contain spaces.
Q4(a) Answer
Question: Write a program to create a hollow pyramid pattern.
n = 5
for i in range(1, n + 1):
for j in range(n - i):
print(" ", end="")
for j in range(1, 2 * i):
if i == n or j == 1 or j == 2 * i - 1:
print("*", end="")
else:
print(" ", end="")
print()
The program uses nested for loops. Spaces are printed to
position the pyramid, while stars are printed only at the boundary
of the pyramid to make it hollow.
Q4(b) Answer
Question: Explain why loops are needed and the types of loops in Python.
Loops are used to execute a block of statements repeatedly until a specified condition is satisfied or the elements of a sequence have been processed.
Python mainly provides the following types of loops:
1. for loop:
A for loop is used to iterate over a sequence such as a
list, tuple, string or range.
for i in range(1, 6):
print(i)
2. while loop:
A while loop repeatedly executes statements as long as
the given condition is true.
i = 1
while i <= 5:
print(i)
i += 1
Q5(a) Answer
Question: Write a function to find the longest word in a given list of words.
def longest_word(words):
longest = words[0]
for word in words:
if len(word) > len(longest):
longest = word
return longest
words = ["apple", "banana", "cherry"]
print(longest_word(words))
Output:
Q5(b) Answer
Question: Distinguish between Tuple and List with examples. Explain with examples at least four built-in methods of Dictionary.
Difference between List and Tuple:
| List | Tuple |
|---|---|
| List is mutable. | Tuple is immutable. |
List is represented using square brackets [ ]. |
Tuple is represented using parentheses ( ). |
| Elements can be changed after creation. | Elements cannot be changed after creation. |
Example: [10, 20, 30] |
Example: (10, 20, 30) |
my_list = [10, 20, 30]
my_list[0] = 50
my_tuple = (10, 20, 30)
print(my_list)
print(my_tuple)
Four Dictionary Built-in Methods:
1. keys(): Returns all keys of the dictionary.
student = {"name": "Amit", "age": 20}
print(student.keys())
2. values(): Returns all values of the dictionary.
print(student.values())
3. items(): Returns key-value pairs.
print(student.items())
4. get(): Returns the value associated with a specified key.
print(student.get("name"))
Q6(a) Answer
Question: Discuss different types of file modes in Python and explain with examples.
File modes specify how a file is opened for an operation. The commonly used file modes are:
| Mode | Description |
|---|---|
r |
Opens a file for reading. |
w |
Opens a file for writing and creates or overwrites the file. |
a |
Opens a file for appending data. |
x |
Creates a new file and gives an error if the file already exists. |
r+ |
Opens a file for both reading and writing. |
w+ |
Opens a file for reading and writing and overwrites the file. |
a+ |
Opens a file for reading and appending. |
file = open("data.txt", "r")
data = file.read()
file.close()
print(data)
Q6(b) Answer
Question: Write a program to read a CSV file and display rows where a specific column value exceeds a given threshold.
import csv
threshold = 50
with open("data.csv", "r") as file:
reader = csv.DictReader(file)
for row in reader:
if float(row["marks"]) > threshold:
print(row)
The program reads the CSV file using DictReader and checks
the value of the specified marks column. Only rows having
marks greater than the threshold are displayed.
Q7(a) Answer
Question: Discuss the role of event handling in Tkinter. How can you bind events? Provide examples.
Event handling in Tkinter is used to perform an action when the user interacts with a graphical user interface. Events may include mouse clicks, key presses and mouse movements.
The bind() method is used to associate an event with a
function.
import tkinter as tk
def click_event(event):
print("Mouse clicked")
root = tk.Tk()
root.title("Event Handling")
root.bind("<Button-1>", click_event)
root.mainloop()
Here, <Button-1> represents a left mouse-button
click. When the event occurs, the click_event() function
is executed.
Q7(b) Answer
Question:
Write a program to read data from CSV students.csv,
calculate average marks for each student and display the results.
import csv
students = {}
with open("students.csv", "r") as file:
reader = csv.DictReader(file)
for row in reader:
name = row["name"]
marks = float(row["marks"])
if name not in students:
students[name] = []
students[name].append(marks)
for name, marks in students.items():
average = sum(marks) / len(marks)
print(name, "Average Marks =", average)
The program reads the student records from the CSV file, stores the marks of each student and calculates the average using:
Download Question Paper and Solutions