Programme Name and Semester: BMT47110
Course Name (Course Code): Python Lab (BMT47110)
Class: BCA -MAWT
Academic Session: 2025-26
Laboratory Manual
(Python Lab)
_____________________________________________________________________________________________
Table of Contents
Module No. Name of the Programs
1. Introduction to I. Write a Python program that takes your name, age, and city as input and
Python Programming displays them with a welcome message using appropriate comments to
[16H] describe each step in your code.
II. Write a Python program that accepts a student's marks in 3 subjects as
strings, converts them to integers using typecasting, calculates the total and
average, and prints the results.
III. Write a Python program that takes two numbers from the user and
performs all arithmetic operations (addition, subtraction, multiplication,
division, floor division, modulus, and exponentiation) and displays the result
of each operation.
Now, modify the previous program to compare both numbers using
comparison operators (==, !=, >, <, >=, <=) and print the result of each
comparison.
IV. Write a Python program to check if a user is eligible to vote. Take age as
input. The person should be 18 or older and a citizen of India. Use logical
operators and display appropriate messages.
Create a Python program that demonstrates the use of:
Identity operators (is, is not) by comparing different variables
Membership operators (in, not in) by checking if a character exists in a
string
V. Write a Python program to demonstrate the use of bitwise operators on
two integers:
AND, OR, XOR, NOT, left shift, right shift.
Display the binary and decimal forms for better understanding.
VI. Write a Python program to take a number as input and determine
whether it is:
Positive
Negative
Zero
Use if-elif-else conditions to solve this.
VII. Write a Python program using a for loop and range() to print the first 10
even numbers. Also calculate and display the sum of these numbers.
Write a Python program using a while loop to reverse a number (e.g.,
input 1234 → output 4321). Use break if the number is zero and use
continue if the digit is 0 (to skip 0s in output).
1
Programme Name and Semester: BMT47110
Course Name (Course Code): Python Lab (BMT47110)
Class: BCA -MAWT
Academic Session: 2025-26
VIII. Write a Python program to repeatedly take input from the user until the
user enters the number 0. Count how many numbers were entered
(excluding 0). Use a while loop and break.
Write a Python program that takes 10 numbers as input (use for loop). Skip
all negative numbers using continue, and display the sum of only the
positive numbers.
Write a Python program with a loop that goes from 1 to 10. If the number is
5, use pass. Print the number in all other cases, and print a message when
the pass is executed.
IX. Write a python program to print the following pattern-
X. Write a program to print all Armstrong numbers between 100 and 1000.
XI. Write a program Using a while loop to find and print the sum of all prime
numbers less than or equal to n.
XII. Write a program to Implement a while loop to repeatedly ask the user for a
number until they enter a negative number. For each entered positive number,
calculate and print its factorial.
2. List, Tuple, I. Write a Python program to create a list of 5 integers.
Dictionary [12H] Display the list
Add a new element at the end
Remove the second element
Sort the list
Find the sum of all elements
II. Given a list L = [10, 20, 30, 40, 50, 60, 70, 80], write a program to:
Print the first 3 elements
Print the last 3 elements
Print every second element
Reverse the list using slicing
III. Write a Python program to accept 3 students’ names and their 3 subject marks using a
nested list. Then:
Calculate average marks of each student
2
Programme Name and Semester: BMT47110
Course Name (Course Code): Python Lab (BMT47110)
Class: BCA -MAWT
Academic Session: 2025-26
Print names of students who scored more than 75 on average
IV. Write a program in Python to create a list of integers then separate odd and even
numbers from the given list.
V. Write a Python program to perform matrix(3x3) multiplication using a list.
VI. Write a program to:
Create a tuple of 5 elements (mix of int, float, and string)
Access elements using positive and negative indexing
Slice the tuple
Try to change an element (showing that tuples are immutable)
VII. Create two tuples: t1 = (1, 2, 3) and t2 = (4, 5, 6)
Write a program to:
Concatenate them
Find the max, min, and length
Check if an element exists using in
VIII. Write a Python program to: Convert a tuple (1, 2, 3) into a list
Modify the second element
Convert it back to a tuple
Then convert the final tuple to a string
IX. Create a dictionary to store the names and marks of 5 students. Write a program to:
Add a new student
Delete a student
Display the marks of a specific student
Print all student names (keys) and marks (values)
X. Write a Python program to create a dictionary with employee IDs as keys and salaries
as values. Then:
Increase salary by 10% for all employees
Display updated dictionary
XI. Take a string input and demonstrate use of at least 5 string methods, such as: upper(),
lower(), replace(), split(), find(), count(), isalpha()
Example: Analyze a sentence like: "Python is easy and powerful."
XII. Write a Python program to check whether a substring exists within a main string or
not. Your program should:
Take two inputs from the user: The main string, The substring to search
Use the in operator or the find() method to check the presence of the substring.
Print an appropriate message:
"Substring found!"
"Substring not found!"
3. Function & I. Write a Python function calculate_stats(numbers) that:
Modules [12H] Accepts a list of integers
Returns a tuple containing: the sum, average, maximum, and minimum
Call the function with a list input and print the result.
II. Write a program to demonstrate the difference between local and global variables.
Use a variable count in both global and function scope
Modify the global variable using global keyword
Display the result before and after calling the function.
III. Write a Python function is_prime(n) to check if a number is prime. Then write
another function print_primes_in_range(start, end) to print all prime numbers
between two limits using the is_prime() function. Write a PYTHON program to
3
Programme Name and Semester: BMT47110
Course Name (Course Code): Python Lab (BMT47110)
Class: BCA -MAWT
Academic Session: 2025-26
check if a number is a palindrome or not using function.
IV. Write a Python function that checks if a number or string is a palindrome, ignoring
spaces and cases (for strings).
Example: Input: "A man a plan a canal Panama" → Output: Palindrome
V. Write a recursive function to compute the nth Fibonacci number.
Use memorization (caching) to optimize the performance.
Then display the first n Fibonacci numbers.
VI. Write two functions:
gcd(a, b) using the Euclidean algorithm
lcm(a, b) using lcm = abs(a*b) // gcd(a, b)
Get two numbers from the user and print both GCD and LCM.
VII. Create a nested dictionary to store employee details:
{
"E001": {"name": "Ayan", "salary": 50000},
"E002": {"name": "Bikram", "salary": 60000}
}
Write a program to update the salary of a specific employee and add a new field
called "bonus".
VIII. Given a dictionary of student names and scores, sort it:
In ascending and descending order by values
Display the sorted output as a list of tuples
Use lambda and sorted().
IX. Write a program that:
Accepts a dictionary from the user (dynamic input of key-value pairs)
Then accepts a key from the user and checks if it exists
If it does, prints its value; if not, allows the user to add it.
X. Given a dictionary of employee IDs and salaries, ask user to:
Enter an ID
If the ID exists, update the salary
Else, print an error message
Use functions to modularize: update_salary(dict, id, new_salary)
XI. Write a Python program to:
Take a string input
Remove punctuation
Count word frequency using a dictionary
Display in sorted order of frequency
Bonus: Allow users to enter multiple lines until a special keyword like 'STOP'.
4. File Handling, OOPS I. Write a Python program to read a text file named [Link] and:
& Event Driven Count the number of words, lines, and characters
Programming [12H] Print the longest line in the file
II. Write a Python program that appends user input to a file called [Link], and also
adds the current date and time with each entry.
III. Create a class BankAccount with:
Attributes: account holder, balance
Methods: deposit, withdraw, show_balance
Demonstrate creating two account objects and performing transactions.
4
Programme Name and Semester: BMT47110
Course Name (Course Code): Python Lab (BMT47110)
Class: BCA -MAWT
Academic Session: 2025-26
IV. Create a base class Student with name and roll number, and a derived class
Marksheet with subject marks and a method to calculate total and percentage.
Display all details using an object.
V. Create a class Employee with attributes: name, department, and salary.
Use:
__init__() to initialize
A class variable to count number of employees
A classmethod to display the total number of employees created.
VI. Design a GUI using tkinter that includes:
Two input fields for numbers
Buttons for Add, Subtract, Multiply, Divide
A label to display the result
VII. Create a login form using tkinter that takes:
Username and Password fields
“Login” button
On clicking “Login”, verify the credentials from a file [Link]
(Each line in the file contains: username, password)
VIII. Create a GUI where users can:
Add a task
Mark a task as done
Delete a task
Store tasks in a file so they persist between runs.
5. Packages [8H] I. Create a NumPy array of size 10 with random integers between 1 and 100. Display:
Maximum, minimum, mean, and standard deviation
Indices of maximum and minimum values.
II. Create a 3×3 NumPy array with values from 1 to 9.
Reshape it into a 1D array
Extract the middle row and last column
Replace all even numbers with 0.
III. Create two 3x3 matrices using NumPy and perform:
Matrix multiplication
Transpose of the resulting matrix
Print all matrices neatly.
IV. Create a 5×5 NumPy array with random integers between 10 and 99.
Perform the following tasks:
Display the array.
Find the row-wise and column-wise sum.
Replace the diagonal elements with -1.
Flatten the array and sort it in descending order.
Count how many elements in the array are prime numbers.
V. Given two NumPy arrays:
a = [Link]([1, 2, 3, 4, 5])
b = [Link]([4, 5, 6, 7, 8])
Perform: Union, Intersection, Set difference (a - b), Symmetric difference.
VI. Use SciPy to compute the definite integral of the function
5
Programme Name and Semester: BMT47110
Course Name (Course Code): Python Lab (BMT47110)
Class: BCA -MAWT
Academic Session: 2025-26
f(x)=x^2+2x+1
from x=0 to x=5
Use [Link].
VII. Use SciPy to solve this system of linear equations:
2𝑥+3𝑥=83𝑥+4𝑥=11
Use [Link].
VIII. Use SciPy to compute the derivative of f(x)=sin(x) at a given point using finite
differences.
IX. Plot the function y=x^2 for x from -10 to 10.
Add title, axis labels
Add grid and legend
Show both the line and scatter points
X. Given a dictionary of student names and marks:
marks = {'Akram': 87, 'Binay': 91, 'Riya': 78, 'Dinesh': 85} Now Plot a bar chart with
proper labels and coloring. Show highest and lowest marks with annotations.