PP LabManual BH23 24batch
PP LabManual BH23 24batch
B.Tech
I Year/ II Sem(BH23)
VISION
To emerge as the best among the institutes of technology and research in the country dedicated to
the cause of promoting quality technical education.
MISSION
At BVRITH, we strive to
VISION
Develop women as technocrats, researchers and entrepreneurs in the field of Computer Science
and Engineering.
MISSION
M1: To impart quality education in Computer Science and Engineering by means of learning
techniques and value-added courses.
M3: To build leadership skills, ethical values and teamwork among the students.
M4: To strengthen the collaboration of department and industry through internships, mentorships
and professional body activities.
After three to six years of graduation, the graduates of this program will be able to:
PEO-1: Develop innovative computing products by utilizing strong technical proficiency and
critical thinking.
PEO-2: Productively engage in research by practicing basic principles grounded in allied areas
of Computer Science and Engineering.
PEO-3: Adapt the emerging technologies to contribute technical innovations for progressive
development.
PEO-4: Demonstrate professionalism, ethical attitude, teamwork and leadership skills with
lifelong learning in the career.
PSO-1 : Ability to apply learned skills to build optimized solutions pertaining to Computer
& Communication Systems, Data Processing and Artificial Intelligence.
PSO-2 : Employ standard strategies and practices in project development using FOSS
(Free Open Source Software).
CSE (AIML) DEPARTMENT VISION & MISSION
VISION
Produce competent technocrats, researchers, and entrepreneurs in Artificial Intelligence &
Machine Learning to build an ecosystem that significantly contributes to the nation
MISSION
M1: To impart skills through various learning methodologies and value-added courses to be
technically competent.
M2: To build the research culture through participations in innovative projects and publications
M3: To inculcate ethics, leadership skills, life skills and lifelong learning
M4: To expose the students to real time environment by internships and mentorships through
collaborations with industries and premier institutions.
After three to six years of graduation, the graduates of this program will be able to:
PEO–1: Adapt emerging technologies to contribute to the technical innovations for the
progressive development in their respective fields.
PEO–2: Productively engage in multidisciplinary research areas by applying the basic principles
of engineering sciences.
PEO–3: Demonstrate strong technical skills to bring out novel designs/products to address the
social & environmental issues.
Course Description: This Course Covers Installation procedure of python and packages. Course
focuses on implementation of different control structures, data structures and Files in Python. It
also helps to implement GUI applications using TKinter.
Course Outcomes: After completion of this course, the students will be able to
C206.1: Build basic programs using fundamental programming constructs.
C206.2: Explore Strings, Lists, Tuples and Dictionaries in Python
C206.3: Develop reusable code and GUI application using standard Library.
C206.4: Implement File I/O and Digital Logic Gates using Python
LIST OF EXPERIMENTS
Cycle 1:
Week - 1:
1. (i) Use a web browser to go to the Python website http://python.org. This page contains
information about Python and links to Python-related pages, and it gives you the ability
to search the Python documentation.
(ii) Start the Python interpreter and type help() to start the online help utility.
(i) Write a program to calculate compound interest when principal, rate and number of
periods are given.
(ii) Given coordinates (x1, y1), (x2, y2) find the distance between two points.
3. Read name, address, email and phone number of a person through keyboard and print the
details.
Week - 2:
1. Find the Euclidean distance with the given values and check the validity of values to find
the distance.
2. Generate a random number between 1-10 and ask the user to guess the number. Give
chance for 3 times. If guessed correctly then congratulate otherwise print message as
sorry.
3. Accept a string and generate the combinations of string until the source string doesn’t
repeated.
4. Generate prime numbers of Fibonacci series between 1-50.
Week - 3:
1. (i) Write a program to convert a list and tuple into arrays.
(ii) Write a program to find common values between two arrays.
2. Write a program to add comma separators in a given big number as per the standard
American convention. Ex: i/p: 100000000 o/p: 100,000,000.
Week - 4:
1. Write a function called is_sorted that takes a list as a parameter and returns True if the list
is sorted in ascending order and False otherwise.
2. Write a function called has_duplicates that takes a list and returns True if there is any
element that appears more than once. It should not modify the original list.
3. (i) Write a function called remove_duplicates that takes a list and returns a new list with
only the unique elements from the original. Hint: they don’t have to be in the same order.
(ii) The wordlist I provided, words.txt, doesn’t contain single letter words. So you might
want to add “I”, “a”, and the empty string.
(iIi) Write a python code to read dictionary values from the user. Construct a function to
invert its content. i.e., keys should be values and values should be keys.
4. (i) Add a comma between the characters. If the given word is 'Apple', it should become
'A,p,p,l,e'.
(ii) Remove the given word in all the places in a string?
(iii) Write a function that takes a sentence as an input parameter and replaces the first
letter of every word with the corresponding upper case letter and the rest of the
letters in the word by corresponding letters in lower case without using a built-in
function?
5. Writes a recursive function that generates all binary strings of n-bit length.
Week - 5:
1. (i) Write a python program that defines a matrix and prints.
(ii) Write a python program to perform addition of two square matrices.
(iii) Write a python program to perform multiplication of two square matrices
2. How do you make a module? Give an example of construction of a module using
different geometrical shapes and operations on them as its functions.
On entering the lab you should make an entry in the log book available with the details regarding
student name, roll no, system no and signature.
Student must bring Observation note book for every lab session. Observation book should be
duly signed by your faculty, failing which your report will not be graded.
Student must complete all experimental programs allotted during the session.
Student should shut down the system properly and leave the lab neat and tidy.
GRADING
For practical subjects there shall be a Continuous Internal Evaluation (CIE) during the semester
for 40 marks and 60 marks for semester end examination.
Out of the 40 marks for internal evaluation:
1. A write-up on day-to-day experiment in the laboratory (in terms of aim, components /
procedure, expected outcome) which shall be evaluated for 10 marks
2. 10 marks for viva-voce (or) tutorial (or) case study (or) application (or) poster presentation of
the course concerned.
3. Internal practical examination conducted by the laboratory teacher concerned shall be
evaluated for 10 marks.
4. The remaining 10 marks are for Laboratory Report / Project and Presentation, which consists
of the Design (or) Software / Hardware Model Presentation (or) App Development (or)
Prototype Presentation submission which shall be evaluated after completion of laboratory
Course and before semester end practical examination.
The Semester End Examination shall be conducted with an external examiner and the laboratory
teacher. The external examiner shall be appointed by the Controller of Examinations / Chief
Superintendent on the recommendation of BoS chairman of the concerned department.
In the Semester End Examination held for 3 hours, total 60 marks are divided and allocated as
shown below:
1. 10 marks for write-up
2. 15 for experiment / program
3. 15 for evaluation of results
4. 10 marks for presentation on another experiment / program in the same laboratory course and
5. 10 marks for viva-voce on concerned laboratory course.
The Student, in each subject, shall have to earn 35% of marks (i.e. 14 marks out of 40 marks) in
CIE, 35% of marks (i.e. 21 marks out of 60) in SEE and overall 40% of marks (i.e. 40 marks out
of 100 marks) both CIE and SEE marks put together.
The student is eligible to write Semester End Examination of the concerned subject, if the
student scores ≥ 35% (14 marks) of 40 Continuous Internal Examination (CIE) marks.
In case, the student appears for Semester End Examination (SEE) of the concerned subject but
not scored minimum 35% of CIE marks (14 marks out of 40 internal marks), her performance in
that subject in SEE shall stand cancelled in spite of appearing the SEE.
The Student, in each subject, shall have to earn 35% of marks (i.e. 14 marks out of 40 marks) in
CIE, 35% of marks (i.e. 21 marks out of 60) in SEE and overall 40% of marks (i.e. 40 marks out
of 100 marks)both CIE and SEE marks put together.
Cycle 1:
Week - 1:
1. (i) Use a web browser to go to the Python website http://python.org. This page
contains information about Python and links to Python-related pages, and it gives you
the ability to search the Python documentation.
(ii) Start the Python interpreter and type help() to start the online help utility.
def addition(num1,num2):
return num1 + num2
def subtraction(num1,num2):
return num1 - num2
def multiplication(num1,num2):
return num1 * num2
def division(num1,num2):
return num1 // num2
def remainder(num1,num2):
return num1 % num2
(iii)Write a program to calculate compound interest when principal, rate and number of
periods are given.
principalAmount = float(input())
rateOfInterest = float(input())
timePeriod = float(input())
CI = principalAmount*(1 + rateOfInterest)**timePeriod # annually compounded
print(CI)
(iv)Given coordinates (x1, y1), (x2, y2) find the distance between two points.
x1,y1,x2,y2 = input().split()
distance = ((int(x1) - int(x2))**2 + (int(y2) - int(y1))**2) ** 0.5
print("%.2f"%distance)
2. Read name, address, email and phone number of a person through keyboard
and print the details.
name=input("enter name:")
address=input("enter address:")
email=input("enter email:")
phonenumber=int(input("enter phone number:"))
print(name)
print(address)
print(email)
print(phonenumber)
Week - 2:
1. Find the Euclidean distance with the given values and check the validity of values to
find the distance.
from scipy.spatial import distance
x1,y1,x2,y2 = input().split()
distance = distance.euclidean((int(x1),int(y1)),(int(x2),int(y2)))
print(distance)
2. Generate a random number between 1-10 and ask the user to guess the number.
Give chance for 3 times. If guessed correctly then congratulate otherwise print
message as sorry.
import random
secretNum = random.randint(1,10)
print(secretNum)
for chance in range(3) :
num = int(input("ENTER A NUMBER BTW 1 TO 10 : "))
if chnce == 2 and num != secretNum :
print("SORRY")
elif num >secretNum :
print("ENTERED NUMBER IS GREATER THAN SECRET NUMBER")
elif num <secretNum :
print("THE ENTERED NUMBER IS LESS THAN THE SECRET NUMBER")
else :
print("CONGRATULATIONS....")
break
3. Accept a string and generate the combinations of string until the source string
doesn’t repeated.
from itertools import permutations
word = input("Enter a string : ")
per = permutations(list(word))
for words in per :
if words != tuple(word):
print("".join(words),end = " ")
Week - 3:
1. (i) Write a program to convert a list and tuple into arrays.
import numpy as np
numList = [int(num) for num in input().split()]
array1 = np.asarray(numList)
print(array1)
num_tup=[int(num) for num in input().split()]
print(np.asarray(num_tup))
(ii) Write a program to find common values between two arrays.
import numpy as np
nums1 = [int(num) for num in input().split()]
nums2 = [int(num) for num in input().split()]
arr1 = np.array(nums1)
arr2 = np.array(nums2)
print(np.intersect1d(arr1,arr2))
2. Write a program to add comma separators in a given big number as per the
standard American convention. Ex: i/p: 100000000 o/p: 100,000,000.
num = int(input())
numList = [num for num in str(num)]
count = 0
for index in range(len(numList) - 1,0,-1) :
count += 1
if count == 3 :
numList.insert(index,",")
count = 0
for num in numList :
print(num,end = "")
import re
def convert_formula(formula):
formula = re.sub(r'(\d)(X|Y)', r'\1*\2', formula)
def distribute(match):
number = match.group(1)
x_term = match.group(2)
y_term = match.group(3)
if y_term:
return f"{number}*{x_term} + {number}*{y_term}"
else:
return f"{number}*{x_term}"
formula = re.sub(r'(\d+)\((X)\+?(Y)?\)', distribute, formula)
return formula
formula1 = "3X+4Y"
formula2 = "3(X+Y)"
a = convert_formula(formula1)
b = convert_formula(formula2)
print(a)
print(b)
Week - 4:
1. Write a function called is_sorted that takes a list as a parameter and returns True if
the list is sorted in ascending order and False otherwise.
def is_sorted(lst):
for i in range (len(lst)-1):
if lst[i]>lst[i+1]:
return False
return True
lst=[int(num) for num in input().split()]
res=is_sorted(lst)
print(res)
2. Write a function called has_duplicates that takes a list and returns True if there is
any element that appears more than once. It should not modify the original list.
def has_duplicates(lst):
seen=set()
for i in lst:
if i in seen:
return True
seen.add(i)
return False
lst=[int(num) for num in input().split()]
res=has_duplicates(lst)
print(res)
5.Writea recursive function that generates all binary strings of n-bit length.
def generate_binary_strings(n):
if n == 1:
return ['0', '1']
else:
prev_strings = generate_binary_strings(n - 1)
new_strings = []
for string in prev_strings:
new_strings.append(string + '0')
new_strings.append(string + '1')
return new_strings
n = int(input("Enter the number of bits (n): "))
binary_strings = generate_binary_strings(n)
print(f"All binary strings of {n}-bit length:")
for binary_string in binary_strings:
print(binary_string)
Week - 5:
1.(i)Write a python program that defines a matrix and prints.
# Creation of matrix
def matrix(rows : int, cols :int) :
matA = []
for index1 in range(0,rows) :
row = []
for index2 in range(0,cols) :
row.append(int(input()))
matA.append(row)
return matA
# Printing matrix
def printMatrix(mat : list[list[int]]) -> None :
for row in range(len(mat)) :
for col in range(len(mat[0])) :
print(mat[row][col],end = " ")
print()
mat = matrix(3,3)
printMatrix(mat)
Week- 7:
1.Write a Python code to merge two given file contents into a third file.
with open("file1","w") as fp1 :
data = "Hello World"
fp1.write(data)
except FileNotFoundError :
print("File not found")
if checkWordInFile("file1","Vaishnavi") :
print("word found")
else :
print("word not found")
3.Write a Python code to Read text from a text file, find the word with most
number of occurrences.
def mostOccurences(file):
try :
with open(file,"r") as fp1 :
data = fp1.read()
occurences = dict()
for word in data.split() :
if word not in occurences :
occurences[word] = 1
else :
occurences[word] += 1
key = max(occurences, key= lambda value: occurences[value])
print(occurences)
return key
except FileNotFoundError :
print("File not found")
mostOccurences("file1")
4.Write a function that reads a file file1 and displays the number of words,
number of vowels, blank spaces, lower case letters and uppercase letters
def analyzeFile(file) -> list[int] :
try :
with open(file,"r") as fp1 :
data = fp1.read()
noOfWords = len(data.split())
noOfVowels = len([char for char in data if char in "aeiou"])
blankSpaces = data.count(" ")
lowerCaseLetters = len([char for char in data if char.islower()])
upperCaseLetters = len([char for char in data if char.isupper()])
return [noOfWords, noOfVowels, blankSpaces,lowerCaseLetters,upperCaseLetters]
except FileNotFoundError:
print("File not Found")
print(analyzeFile("file1"))
WEEK – 8:
1.Import Numpy, Plotpy and Scipy and explore their functionalities.
import numpy as np
import plotly.graph_objects as go
from scipy import stats
# Numpy
array = np.array([1, 2, 3])
print("Numpy array:", array)
# Plotly
fig = go.Figure(data=go.Scatter(x=[1, 2, 3], y=[1, 4, 9], mode='markers'))
fig.show()
# Scipy
data = [1, 2, 3, 4, 5]
mean = stats.tmean(data)
print("Mean of data using Scipy:", mean)
3.Write a program to implement Digital Logic Gates – AND, OR, NOT, EX-
OR.
def AND(a, b):
return a and b
def OR(a, b):
return a or b
def NOT(a):
return not a
def XOR(a, b):
return a ^ b
# Example inputs
num1 = int(input("Enter first binary input (0 or 1): "))
num2 = int(input("Enter second binary input (0 or 1): "))
# Validate inputs
if num1 not in (0, 1) or num2 not in (0, 1):
print("Invalid input. Please enter 0 or 1.")
else:
# AND gate
print(f"AND({num1}, {num2}) = {AND(num1,num2)}")
# OR gate
print(f"OR({num1}, {num2}) = {OR(num1,num2)}")
# NOT gate (applied only to the first input for demonstration)
print(f"NOT({num1}) = {int(NOT(num1))}")
# XOR gate
print(f"XOR({num1}, {num2}) = {XOR(num1,num2)}")
5.Write a GUI program to create a window wizard having two text labels, two
text fields and two buttons as Submit and Reset.
from tkinter import Tk, Label, Entry, Button
def submit():
print("Submitted")
def reset():
entry1.delete(0, 'end')
entry2.delete(0, 'end')
root = Tk()
root.title("Window Wizard")
label1 = Label(root, text="Label 1")
label1.pack()
entry1 = Entry(root)
entry1.pack()
label2 = Label(root, text="Label 2")
label2.pack()
entry2 = Entry(root)
entry2.pack()
submit_button = Button(root, text="Submit", command=submit)
submit_button.pack()
reset_button = Button(root, text="Reset", command=reset)
reset_button.pack()
root.mainloop()
Viva Questions
Q18.What is pep 8?
Ans: PEP stands for Python Enhancement Proposal. It is a set of rules that specify how to format
Python code for maximum readability.