FREE E LEARNING PLATFORM
☰ HOMEEXCEPTIONSOOPSJVMINTRO
×

Python Syllabus

AKTU Python Syllabus AKTU Python Freshers AKTU Python Advanced AKTU Pyton PYQ AKTU Pyton PYQS 2026 AKTU Pyton PYQS 2025 AKTU Pyton PYQS 2024

Unit I Introduction

Introduction to Python History of Python Features of Python Applications of Python Python Installation Python IDE Python Program Life Cycle First Python Program Blocks & Indentation Comments Keywords Identifiers Variables Input & Output Data Types Numeric Data Types Type Conversion Python Operators

Unit II Control Statements

if Statement if...else Statement Nested if elif Statement for Loop range() Function while Loop Nested Loops break Statement continue Statement pass Statement else with Loop

Unit III Complex Data Types

Strings String Operations String Methods String Built-in Functions Lists List Slicing List Methods List Built-in Functions Tuples Tuple Methods Dictionaries Dictionary Methods Dictionary Built-in Functions Python Built-in Functions Python Functions User Defined Functions Lambda Functions Recursive Functions

Unit IV File Handling

Introduction to File Handling open() read() readline() readlines() write() writelines() File Pointer seek() tell() File Modes

Unit V Packages & GUI

Modules Packages NumPy Pandas Matplotlib Tkinter Introduction Tkinter Widgets Button Widget Label Widget Entry Widget Frame Widget Menu Widget Event Handling Programming with IDE Tkinter Mini Project

Python Programs

100+ Solved Programs Pattern Programs File Programs Tkinter Programs

AKTU Questions

Unit I Questions Unit II Questions Unit III Questions Unit IV Questions Unit V Questions Viva Questions Python MCQs

Previous Papers

AKTU 2026 (Solved) AKTU 2025 (Solved) AKTU 2024 (Solved) AKTU 2023 (Solved) AKTU 2022 (Solved)
 


AKTU Python Programming Question Paper 2024

BCC302 – Python Programming
B.Tech Semester III | AKTU Theory Examination

Time: 3 Hours    |    Maximum Marks: 70

AKTU BCC302 Python Programming – 2024 Question Paper

This page provides the English version of the AKTU B.Tech BCC302 Python Programming question paper for 2024, along with detailed exam-oriented solutions.

Note: The original university question paper contains both English and Hindi. The questions and solutions displayed on this page are in English.

Question Paper Index

Section Question Marks
Section A 1(a) List comprehension with example 2
1(b) Difference between / and // operators 2
1(c) Output of the given Python program 2
1(d) Using functions defined in library.py in main.py 2
1(e) Difference between linspace and arqspace 2
1(f) Error in the given Python program 2
1(g) Functions of matplotlib and pandas 2
Section B 2(a) Tuple unpacking, mutable sequences and string concatenation 7
2(b) List slicing constructs and list operations 7
2(c) Function to check a perfect square 7
2(d) Reverse file contents and separate characters by comma 7
2(e) Plot the given food dataset using Matplotlib 7
Section C 3(a) Remove nth character from a string 7
3(b) Sort comma-separated words alphabetically 7
4(a) Validate passwords using specified criteria 7
4(b) Working of while and for loops 7
5(a) Find the smallest list from a nested list 7
5(b) Implement filters to clean text 7
6(a) Change numbers in a file to text 7
6(b) Print words composed of digits only 7
7(a) Read cities.csv, separate last column and plot first two columns 7
7(b) Design a calculator using buttons and required operations 7

SECTION A

Q1. Attempt all questions in brief. (2 × 7 = 14)

Q1(a). Describe the concept of list comprehension with a suitable example.

Answer: List comprehension is a concise way of creating a new list from an existing iterable such as a list, tuple or range. It generally contains an expression followed by a for loop and may also contain a condition.


numbers = [1, 2, 3, 4, 5]

squares = [x * x for x in numbers]

print(squares)
Output:
[1, 4, 9, 16, 25]

Q1(b). Differentiate between / and // operator with an example.

Answer: The / operator performs normal division and returns the quotient as a floating-point value. The // operator performs floor division and returns the greatest integer less than or equal to the quotient.


print(17 / 5)
print(17 // 5)
Output:
3.4
3

Q1(c). Compute the output of the following Python code:


def count(s):
    for str in string.split():
        s = "&".join(str)

    return s

print(count("Python is fun to learn."))

Answer: As printed in the question paper, the program uses string.split(), but string has not been defined. Therefore, the program generates a NameError.

Output / Error:
NameError: name 'string' is not defined

The error occurs because the function parameter is named s, whereas the program attempts to use string.

Q1(d). How to use the functions defined in library.py in main.py

Answer: Functions defined in another Python file can be used by importing that file as a module.

For example, suppose library.py contains:


# library.py

def add(a, b):
    return a + b

The function can be used in main.py as follows:


# main.py

import library

print(library.add(10, 20))
Output: 30

Q1(e). Describe the difference between linspace and arqspace.

Answer: The question paper mentions arqspace. This appears to refer to a NumPy spacing function. The commonly used NumPy functions for this purpose are linspace() and arange().

linspace() generates a specified number of equally spaced values between a start and stop value.

arange() generates values using a specified step size.


import numpy as np

print(np.linspace(0, 10, 5))

print(np.arange(0, 10, 2))
Output:
[ 0.   2.5  5.   7.5 10. ]
[0 2 4 6 8]

Q1(f). Explain why the program generates an error.


x = ['12', 'hello', 456]

x[0] *= 3

x[1][1] = 'bye'

Answer: The statement x[0] *= 3 is valid because strings support repetition. Therefore, '12' becomes '121212'.

The error occurs in the statement:


x[1][1] = 'bye'

Here, x[1] is the string "hello". Strings are immutable in Python, so an individual character of a string cannot be changed using assignment.

Error:
TypeError: 'str' object does not support item assignment

Q1(g). Describe about different functions of matplotlib and pandas.

Answer: Matplotlib is a Python library used for creating graphs and charts. Some commonly used functions are:

  • plot() – creates line plots.
  • bar() – creates bar charts.
  • scatter() – creates scatter plots.
  • pie() – creates pie charts.
  • hist() – creates histograms.

Pandas is used for data manipulation and analysis. Some commonly used functions and methods are:

  • read_csv() – reads data from a CSV file.
  • head() – displays the first few records.
  • describe() – provides statistical information.
  • drop() – removes rows or columns.
  • to_csv() – saves data into a CSV file.

Next: Section B – Q2(a) to Q2(e)

SECTION C

Q3. Attempt any one part of the following.

Q3(a). Determine a Python function removenth(s,n) that takes an input a string and an integer n >= 0 and removes a character at index n. If n is beyond the length of s, then whole s is returned.

Answer: The function checks whether the given index is within the valid range of the string. If the index is valid, the character at that position is removed using string slicing. If the index is beyond the length of the string, the original string is returned.


def removenth(s, n):

    if n < 0 or n >= len(s):
        return s

    return s[:n] + s[n + 1:]


print(removenth("MANGO", 1))
print(removenth("MANGO", 3))
Output:
MNGO
MANO

For n = 1, the character A is removed from MANGO. For n = 3, the character G is removed.

Q3(b). Construct a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.

Answer: The input is first divided into individual words using split(","). The words are then sorted using the sort() method and joined again using commas.


words = input("Enter words: ").split(",")

words = [word.strip() for word in words]

words.sort()

print(", ".join(words))

For the given input:

without, hello, bag, world

The output will be:

bag, hello, without, world

Q4. Attempt any one part of the following.

Q4(a). A website requires the users to input username and password to register. Construct a program to check the validity of password input by users.

Answer: The password must satisfy all the conditions given in the question:

  1. At least one lowercase letter between [a-z].
  2. At least one number between [0-9].
  3. At least one uppercase letter between [A-Z].
  4. At least one character from [$#@].
  5. Minimum length must be 6.
  6. Maximum length must be 12.

Regular expressions can be used to check these conditions. The program accepts comma-separated passwords and prints only the valid passwords.


import re

passwords = input("Enter passwords: ").split(",")

valid_passwords = []

for password in passwords:

    password = password.strip()

    if (6 <= len(password) <= 12
        and re.search(r"[a-z]", password)
        and re.search(r"[0-9]", password)
        and re.search(r"[A-Z]", password)
        and re.search(r"[$#@]", password)):

        valid_passwords.append(password)


print(",".join(valid_passwords))

The re.search() function checks whether the required lowercase letter, digit, uppercase letter and special character are present.

Q4(b). Explore the working of while, and for loop with examples.

Answer: Loops are used to execute a block of statements repeatedly. Python mainly provides for and while loops.

1. while loop: A while loop executes its statements repeatedly as long as its condition is true.


i = 1

while i <= 5:

    print(i)

    i += 1
Output:
1
2
3
4
5

2. for loop: A for loop is used to iterate over a sequence or a range of values.


for i in range(1, 6):

    print(i)
Output:
1
2
3
4
5

Thus, a while loop is generally condition-controlled, whereas a for loop is commonly used for iterating over a sequence or range.


Q5. Attempt any one part of the following.

Q5(a). Construct a function ret_smaller(l) that returns smallest list from a nested list. If two lists have same length then return the first list that is encountered.

Answer: The length of each list in the nested list is compared. The first list is initially considered the smallest. It is replaced only when a list having a smaller length is found.


def ret_smaller(l):

    smallest = l[0]

    for item in l[1:]:

        if len(item) < len(smallest):
            smallest = item

    return smallest


print(ret_smaller([
    [-2, -1, 0, 0.12, 1, 2],
    [3, 4, 5],
    [6, 7, 8, 9, 10],
    [11, 12, 13, 14, 15]
]))
Output:
[3, 4, 5]

For the second example given in the question:


print(ret_smaller([
    [-2, -1, 0, 0.12, 1, 2],
    ['a', 'b', 'c', 'd', 3, 4, 5],
    [6, 7, 8, 9, 10],
    [11, 12, 13, 14, 15]
]))
Output:
[6, 7, 8, 9, 10]

If two lists have the same length, the function does not replace the first list because the comparison uses <. Therefore, the first encountered list is retained.

Q5(b). Construct following filters.

  1. Filter all the numbers.
  2. Filter all the strings starting with a vowel.
  3. Filter all the strings that contains any of the following noun: Agra, Ramesh, Tomato, Patna.

Answer: The following program applies the required filters to a list of data items.


data = [
    "123",
    "Agra",
    "apple",
    "Ramesh",
    "Tomato",
    "Patna",
    "Delhi",
    "45"
]


numbers = []

vowel_strings = []

specified_strings = []


for item in data:

    text = str(item)


    # Filter numbers

    if text.isdigit():
        numbers.append(item)


    # Strings starting with a vowel

    if text and text[0].lower() in "aeiou":
        vowel_strings.append(item)


    # Specified words

    if any(word.lower() in text.lower()
           for word in ["Agra", "Ramesh",
                        "Tomato", "Patna"]):

        specified_strings.append(item)


print("Numbers:", numbers)

print("Strings starting with vowel:",
      vowel_strings)

print("Specified strings:",
      specified_strings)

The program separately stores the numbers, strings beginning with a vowel and strings containing any of the specified words.


Q6. Attempt any one part of the following.

Q6(a). Change all the numbers in the file to text. Construct a program for the same.

Answer: The numbers present in a text file can be identified using a regular expression. Each digit can then be replaced by its corresponding English word.


import re


number_words = {
    "0": "zero",
    "1": "one",
    "2": "two",
    "3": "three",
    "4": "four",
    "5": "five",
    "6": "six",
    "7": "seven",
    "8": "eight",
    "9": "nine"
}


with open("input.txt", "r") as file:

    text = file.read()


def replace_number(match):

    number = match.group()

    return " ".join(number_words[digit]
                    for digit in number)


text = re.sub(r"\d+", replace_number, text)


with open("output.txt", "w") as file:

    file.write(text)


print(text)

For example, the number 10 will be converted into:

one zero

Q6(b). Construct a program which accepts a sequence of words separated by whitespace as file input. Print the words composed of digits only.

Answer: The file is read and divided into words using the split() method. The isdigit() method is then used to identify words containing digits only.


with open("input.txt", "r") as file:

    words = file.read().split()


for word in words:

    if word.isdigit():

        print(word)

For example, if the file contains:

Python 123 programming 456
BTech 789

The output will be:

123
456
789

Q7. Attempt any one part of the following.

Q7(a). Construct a program to read cities.csv dataset, remove last column and save it in an array. Save the last column to another array. Plot the first two columns.

Answer: The CSV file can be read using Pandas. The last column is separated and the remaining columns are stored in another array. The first two columns are then plotted using Matplotlib.


import pandas as pd
import matplotlib.pyplot as plt


data = pd.read_csv("cities.csv")


# Remove and save the last column

main_data = data.iloc[:, :-1].to_numpy()

last_column = data.iloc[:, -1].to_numpy()


print("Main Array:")
print(main_data)

print("Last Column:")
print(last_column)


# Plot first two columns

plt.scatter(
    main_data[:, 0],
    main_data[:, 1]
)

plt.xlabel(data.columns[0])

plt.ylabel(data.columns[1])

plt.title("First Two Columns")

plt.show()

Here, main_data contains all columns except the last column, while last_column contains the last column. The first two columns of main_data are plotted using a scatter plot.

Q7(b). Design a calculator with the following buttons and functionalities like addition, subtraction, multiplication, division and clear.

Answer: A graphical calculator can be developed using the Tkinter library. An Entry widget is used to display the expression and buttons are provided for numbers and arithmetic operations.


import tkinter as tk


def click(value):

    entry.insert(tk.END, value)


def calculate():

    try:

        result = eval(entry.get())

        entry.delete(0, tk.END)

        entry.insert(0, result)

    except:

        entry.delete(0, tk.END)

        entry.insert(0, "Error")


def clear():

    entry.delete(0, tk.END)


root = tk.Tk()

root.title("Calculator")


entry = tk.Entry(
    root,
    width=25,
    font=("Arial", 16)
)

entry.grid(
    row=0,
    column=0,
    columnspan=4,
    padx=10,
    pady=10
)


buttons = [

    ("7", 1, 0),
    ("8", 1, 1),
    ("9", 1, 2),
    ("/", 1, 3),

    ("4", 2, 0),
    ("5", 2, 1),
    ("6", 2, 2),
    ("*", 2, 3),

    ("1", 3, 0),
    ("2", 3, 1),
    ("3", 3, 2),
    ("-", 3, 3),

    ("0", 4, 0),
    (".", 4, 1),
    ("+", 4, 2)
]


for text, row, column in buttons:

    tk.Button(
        root,
        text=text,
        width=5,
        command=lambda x=text: click(x)
    ).grid(
        row=row,
        column=column,
        padx=3,
        pady=3
    )


tk.Button(
    root,
    text="=",
    width=5,
    command=calculate
).grid(
    row=4,
    column=3,
    padx=3,
    pady=3
)


tk.Button(
    root,
    text="Clear",
    width=23,
    command=clear
).grid(
    row=5,
    column=0,
    columnspan=4,
    padx=3,
    pady=5
)


root.mainloop()

The program creates a calculator window with buttons for numbers, addition, subtraction, multiplication, division, equals and clear. The click() function inserts the selected value into the Entry widget, while calculate() performs the calculation and clear() removes the current expression.


AKTU BCC302 Python Programming 2024 – Complete Solutions

Complete solutions for all questions from Section A, Section B and Section C have been provided above.

Download Question Paper and Solutions

Download the original AKTU question paper and the complete solved question paper for offline examination preparation.