0% found this document useful (0 votes)
2 views

2nd SemPython LabManual-25

The document is a lab manual for the 'Introduction to Python Programming' course at Don Bosco Institute of Technology, detailing the course objectives, outcomes, and programming exercises for students. It outlines the evaluation criteria for Continuous Internal Evaluation (CIE) and Semester End Examination (SEE) along with suggested learning resources. The manual includes specific programming tasks designed to enhance students' understanding of Python concepts and practical applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

2nd SemPython LabManual-25

The document is a lab manual for the 'Introduction to Python Programming' course at Don Bosco Institute of Technology, detailing the course objectives, outcomes, and programming exercises for students. It outlines the evaluation criteria for Continuous Internal Evaluation (CIE) and Semester End Examination (SEE) along with suggested learning resources. The manual includes specific programming tasks designed to enhance students' understanding of Python concepts and practical applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Visvesvaraya Technological University

“Jnana Sangama”, Belagavi - 590018

INTRODUCTION TO PYTHON PROGRAMMING


(BPLCK105B/205B)

Lab Manual
For
I Semester B E/II Semester BE

Prepared by
Dr. Rajshekhar .M. Patil , Professor , Dept of ISE
Smt. Yamunashree. Asst. Professor , Dept of ISE
Smt. Yashodhara , Asst. Professor Dept of ISE
Kirankumar Asst. Professor , Dept of ISE

Don Bosco Institute Of Technology - 560074


Department of Computer Science and Engineering
2024-2025
Don Bosco Institute of Technology
Department of Computer Science & Engineering

Vision: To be a center of excellence to transform young minds in technical and management


education, fostering innovation and entrepreneurial skills with ethical , environment and social
responsibility

Mission:
M1. To impart quality education in order to meet the needs of industry and society.

M2. To collaborate with academia, industry and research institutes to strengthen


teaching and learning process.
M3. To promote equitable and harmonious development of students to work in
teams.
M4. To imbibe lifelong learning skills and entrepreneurial skills exhibiting
leadership.

Program Educational Objectives:


PEO1: Graduates with acquired engineering knowledge will be able to
comprehend, analyze, design, and create software solutions for real time problems.

PEO2: Graduates will work individually and in team for software project management.

PEO3: Graduates will be able to grow professionally by enhancing their knowledge


and skills by lifelong learning.

PEO4: Graduates will exhibit ethical entrepreneurial skills.

Program Specific Outcomes:


PSO1: An ability to analyze algorithms and codes.

PSO2: An ability to design, develop and implement algorithms for real time applications.
PSO3: An ability to develop mobile and web applications.
PSO4: An ability to inculcate professional skills, entrepreneurship skills, and work in teams for
developing engineering solutions for societal needs with ethical practices.
Program Outcomes (POs)
Engineering Graduates will be able to:
• Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering problems.

• Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.

• Design/development of solutions: Design solutions for complex engineering problems and


design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.

• Conduct investigations of complex problems: Use research-based knowledge and research


methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.

• Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.

• The Engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.

• Environment and sustainability: Understand the impact of the professional engineering


solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.

• Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.

• Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.

• Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.

• Project management and finance: Demonstrate knowledge and understanding of the


engineering and management principles and apply these to one‟s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
• Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

Course Outcomes (COs):

CO# Description
Demonstrate proficiency in handling loops and creation of functions.
CO1

CO2 Identify the methods to create and manipulate lists, tuples and dictionaries.

CO3 Develop programs for string processing and file organization

CO4 Interpret the concepts of object oriented programming as used in python


Don Bosco Institute of Technology

Department of Computer Science and Engineering

Introduction to Python Programming: Lab Manual

Course Name: Introduction to Python Course Code: Sem/Sec:IInd


Programming BPLCK205B

Programming Exercises:

1. a. Develop a program to read the student details like Name, USN, and Marks in
three subjects. Display the student details, total marks and percentage with suitable
messages.

b. Develop a program to read the name and year of birth of a person. Display whether
the person is a senior citizen or not.

2. a. Develop a program to generate Fibonacci sequence of length (N). Read N from


the console.

b. Write a function to calculate factorial of a number. Develop a program to compute


binomial coefficient (Given N and R).

3. Read N numbers from the console and create a list. Develop a program to print
mean, variance and standard deviation with suitable messages.

4. Read a multi-digit number (as chars) from the console. Develop a program to print
the frequency of each digit with suitable message.

5. Develop a program to print 10 most frequently appearing words in a text file. [Hint:
Use dictionary with distinct words and their frequency of occurrences. Sort the
dictionary in the reverse order of frequency and display dictionary slice of first 10
items]

6. Develop a program to sort the contents of a text file and write the sorted contents
into a separate text file. [Hint: Use string methods strip(), len(), list methods sort(),
append(), and file methods open(), readlines(), and write()].

7. Develop a program to backing Up a given Folder (Folder in a current working


directory) into a ZIP File by using relevant modules and suitable methods.

8. Write a function named DivExp which takes TWO parameters a, b and returns a
value c (c=a/b). Write suitable assertion for a>0 in function DivExp and raise an
exception for when b=0. Develop a suitable program which reads two values from the
console and calls a function DivExp.
9. Define a function which takes TWO objects representing complex numbers and
returns new complex number with an addition of two complex numbers. Define a
suitable class „Complex‟ to represent the complex number. Develop a program to read
N (N >=2) complex numbers and to compute the addition of N complex numbers.

10. Develop a program that uses class Student which prompts the user to enter marks
in three subjects and calculates total marks, percentage and displays the score card
details. [Hint: Use list to store the marks in three subjects and total marks. Use
init () method to initialize name, USN and the lists to store marks and total, Use
getMarks() method to read marks into the list, and display() method to display the
score card details.]

Assessment Details (both CIE and SEE)

The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End
Exam (SEE) is 50%. The minimum passing mark for the CIE is 40% of the maximum
marks (20 marks out of 50). The minimum passing mark for the SEE is 35% of the
maximum marks (18 marks out of 50). A student shall be deemed to have satisfied the
academic requirements and earned the credits allotted to each subject/ course if the
student secures not less than 35% (18 Marks out of 50) in the semester-
endexamination (SEE), and a minimum of 40% (40 marks out of 100) in the sum total
of the CIE (Continuous Internal Evaluation) and SEE (Semester End Examination)
taken together. Continuous Internal Evaluation (CIE):The CIE marks for the theory
component of the IC shall be 30 marks and for the laboratory component 20 Marks.

CIE for the theory component of the IC

 Three Tests each of 20 Marks; after the completion of the syllabus of 35-40%,
65-70%, and 90-100% respectively.
 Two Assignments/two quizzes/ seminars/one field survey and report
presentation/one course project totaling 20 marks.

Total Marks scored (test + assignments) out of 80 shall be scaled down to 30 marks

CIE for the practical component of the IC

On completion of every experiment/program in the laboratory, the students shall be


evaluated and marks shall be awarded on the same day. The 15 marks are for
conducting the experiment and preparation of the laboratory record, the other 05
marks shall be for the test conducted at the end of the semester.

The CIE marks awarded in the case of the Practical component shall be based on the
continuous evaluation of the laboratory report. Each experiment report can be
evaluated for 10 marks. Marks of all experiments‟ write-ups are added and scaled
down to 15 marks.
The laboratory test (duration 03 hours) at the end of the 15th week of the semester
/after completion of all the experiments (whichever is early) shall be conducted for 50
marks and scaled down to 05 marks.

Scaled-down marks of write-up evaluations and tests added will be CIE marks for the
laboratory component of IC/IPCC for 20 marks.

The minimum marks to be secured in CIE to appear for SEE shall be 12 (40% of
maximum marks) in the theory component and 08 (40% of maximum marks) in the
practical component. The laboratory component of the IC/IPCC shall be for CIE only.

However, in SEE, the questions from the laboratory component shall be included. The
maximum of 05 questions is to be set from the practical component of IC/IPCC, the
total marks of all questions should not be more than 25 marks. The theory component
of the IC shall be for both CIE and SEE.

Semester End Examination (SEE):

SEE for IC

Theory SEE will be conducted by university as per the scheduled time table, with
common question papers for the course (duration 03 hours)

1. The question paper will have ten questions. Each question is set for 20 marks.

2. There will be 2 questions from each module. Each of the two questions under a
module (with a maximum of 3 sub-questions), should have a mix of topics under that
module.

3. The students have to answer 5 full questions, selecting one full question from each
module. The theory portion of the Integrated Course shall be for both CIE and SEE,
whereas the practical portion will have a CIE component only. Questions mentioned
in the SEE paper shall include questions from the practical component).

Passing standard:

The minimum marks to be secured in CIE to appear for SEE shall be 12 (40% of
maximum marks-30) in the theory component and 08 (40% of maximum marks -20)
in the practical component. The laboratory component of the IPCC shall be for CIE
only. However, in SEE, the questions from the laboratory component shall be
included. The maximum of 04/05 questions to be set from the practical component of
IPCC, the total marks of all questions should not be more than 30 marks.

SEE will be conducted for 100 marks and students shall secure 35% of the maximum
marks to qualify for the SEE. Marks secured will be scaled down to 50.

Suggested Learning Resources:


Text Books

1. Al Swigert, “Automate the Boring Stuff with Python”,1stEdition, No Starch Press,


2015. (Available under CC-BY-NC-SA license atttps://automatetheboringstuff.com/)
(Chapters 1 to 18, except 12) for lambda functions use this link:
https://www.learnbyexample.org/python-lambda-function/

2. Allen B. Downey, “Think Python: How to Think Like a Computer Scientist”, 2nd
Edition, Green Tea Press, 2015. (Available under CC-BY-NC license at
http://greenteapress.com/thinkpython2/thinkpython2.pdf(Chapters 13, 15, 16, 17, 18)
(Download pdf/html files from the above link)
Programming Exercises:

1a. Develop a program to read the student details like Name, USN, and Marks in three subjects.
Display the student details, total marks and percentage with suitable messages.

stName = input("Enter the name of the student : ")


stUSN = input("Enter the USN of the student : ")
stMarks1 = int(input("Enter marks in Subject 1 : "))
stMarks2 = int(input("Enter marks in Subject 2 : "))
stMarks3 = int(input("Enter marks in Subject 3 : "))
print("Student Details\n=========================")
print( "Name :", stName)
print("USN :", stUSN)
print("Marks 1 :", stMarks1)
print("Marks 2 :", stMarks2)
print("Marks 3 :", stMarks3)
print("Total :", stMarks1+stMarks2+stMarks3)
print("Percent :","%0.2f"%((stMarks1+stMarks2+stMarks3)/3))
print("=========================")
OUTPUT:
Enter the name of the student: Raju
Enter the USN of the student: 1JS22CSE001
Enter marks in Subject 1: 67
Enter marks in Subject 2: 77
Enter marks in Subject 3: 99
Student Details
=======================

Name: Raju
USN: 1JS22CSE001
Marks 1: 67
Marks 2: 77
Marks 3: 99
Total: 243
Percent : 81.00
1b. Develop a program to read the name and year of birth of a person. Display whether the
person is a senior citizen or not.
perName = input("Enter the name of the person : ")
perDOB = int(input("Enter his year of birth : "))
curYear = int(input("Enter current year : "))
perAge = curYear - perDOB
if (perAge > 60):
print(perName, "aged", perAge, "years is a Senior Citizen.")
else:
print(perName, "aged", perAge, "years is not a Senior Citizen.")

OUTPUT:
Enter the name of the person : Rani
Enter his year of birth : 1947
Enter current year : 2023
Rani aged 76 years is a Senior Citizen.
2a. Develop a program to generate Fibonacci sequence of length (N). Read N from the console.
num = int(input("Enter the Fibonacci sequence length to be generated : "))
firstTerm = 0
secondTerm = 1
print("The Fibonacci series with", num, "terms is :")
print(firstTerm, secondTerm, end=" ")
for i in range(2,num):
curTerm = firstTerm + secondTerm
print(curTerm, end=" ")
firstTerm = secondTerm
secondTerm = curTerm

OUTPUT:
Enter the Fibonacci sequence length to be generated : 9
The Fibonacci series with 9 terms is :
0 1 1 2 3 5 8 13 21
2b. Write a function to calculate factorial of a number. Develop a program to compute binomial
co- efficient (Given N and R).

def fact(num):
if num == 0:
return 1
else:
return num * fact(num-1)

n = int(input("Enter the value of N : "))


r = int(input("Enter the value of R (R cannot be negative or greater than N): "))
nCr = fact(n)/(fact(r)*fact(n-r))
print(n,"C",r," = ",nCr,sep="")

OUTPUT:
Enter the value of N : 5
Enter the value of R (R cannot be negative or greater than N): 3
5C3 = 10.0
3. Read N numbers from the console and create a list. Develop a program to print mean,
variance and standard deviation with suitable messages.
from math import sqrt
myList = []
num = int(input("Enter the number of elements in your list : "))
for i in range(num):
val = int(input("Enter the element : "))
myList.append(val)
print('The length of list1 is', len(myList))
print('List Contents', myList)
total = 0
for elem in myList:
total += elem
mean = total / num
total = 0
for elem in myList:
total += (elem - mean) * (elem - mean)
variance = total / num
stdDev = sqrt(variance)
print("Mean =", mean)
print("Variance =", variance)
print("Standard Deviation =", "%.2f"%stdDev)
OUTPUT:
Enter the number of elements in your list : 5
Enter the element : 12
Enter the element : 55
Enter the element : 34
Enter the element : 78
Enter the element : 11
The length of list1 is 5
List Contents [12, 55, 34, 78, 11]
Mean = 38.0
Variance = 662.0
Standard Deviation = 25.73
4. Read a multi-digit number (as chars) from the console. Develop a program to print the
frequency of each digit with suitable message..

num = input("Enter a number : ")


print("The number entered is :", num)
uniqDig = set(num)
for elem in uniqDig:
print(elem, "occurs", num.count(elem), "times")

OUTPUT:
The number entered is : 123343
2 occurs 1 times
4 occurs 1 times
1 occurs 1 times
3 occurs 3 times
5. Develop a program to print 10 most frequently appearing words in a text file. [Hint: Use
dictio- nary with distinct words and their frequency of occurrences. Sort the dictionary in the
reverse order of frequency and display dictionary slice of first 10 items]
fname=input('Enter file directory/name: ')
c=[]
d={}
with open(fname,'r') as f:
content=f.read()
word=content.split()

for i in word:
c.append(i)

for i in c:
count=0
for j in c:
if i==j:
count+=1
d[i]=count

sortd=sorted(d.items(), key=lambda x:x[1], reverse=True)


print(sortd[0:10])

OUTPUT:
Enter file directory/name: SORT.TXT
[('1', 1), ('2', 1), ('3', 1), ('8', 1), ('5', 1), ('6', 1), ('7', 1)]
6. Develop a program to sort the contents of a text file and write the sorted contents into a
separate text file. [Hint: Use string methods strip(), len(), list methods sort(), append(), and file
methods open(), readlines(), and write()].
fname=input('Enter file name/directory: ')
with open(fname,'r') as f:
read=f.read()
word=read.split()
l=[]
for i in word:
l.append(i)
l.sort()
wname=input('Enter file name to create: ')
with open(wname,'w') as w:
for j in l:
w.write(j)
w.write('\n')

OUTPUT:
Enter file name/directory: sort.txt
Enter file name to create: sort1.txt
7. Develop a program to backing Up a given Folder (Folder in a current working directory) into
a ZIP File by using relevant modules and suitable methods.

import shutil
name=input('Enter zip file name: ')
directory=input('Enter file directory: ')
shutil.make_archive(name,'zip',directory)

OUTPUT:
Enter zip file name: SORT.TXT
Enter file directory: python 1st year
8. Write a function named DivExp which takes TWO parameters a, b and returns a value c
(c=a/b). Write a suitable assertion for a>0 in function DivExp and raise an exception for when
b=0. Develop a suitable program which reads two values from the console and calls a function
DivExp.

def DivExp(a,b):
if b==0:
print('Error. Integer Overflow')
else:
c=a/b
return c

a=int(input('Enter first integer: '))


b=int(input('Enter second integer: '))

print(DivExp(a,b))

OUTPUT:

Enter first integer: 3


Enter second integer: 0
Error. Integer Overflow
None

Enter first integer: 12


Enter second integer: 4
3.0
9. Define a function which takes TWO objects representing complex numbers and returns a new
complex number with an addition of two complex numbers. Define a suitable class „Complex‟ to
represent the complex number. Develop a program to read N (N >=2) complex numbers and to
compute the addition of N complex numbers.
class Complex():
def init (self, a, b):
self.a=a
self.b=b

def add(self):
print(self.a+self.b)

n=int(input('Enter number: '))


if n>=2:
for i in range(n):
a=complex(input('Enter first complex number: '))
b=complex(input('Enter second complex number: '))
a1=Complex(a,b)
a1.add()
else:
print('Invalid input. Enter number greater than 2')

OUTPUT:
Enter number: 12
Enter first complex number: 12.364
Enter second complex number: 15.486
(27.85+0
10. Develop a program that uses class Student which prompts the user to enter marks in three
subjects and calculates total marks, percentage and displays the score card details. [Hint: Use
list to store the marks in three subjects and total marks. Use init () method to initialize
name, USN and the lists to store marks and total, Use getMarks() method to read marks into the
list, and display() method to display the score card details.]

class Student():
def init (self, name, usn):
self.name=name
self.usn=usn
self.marks=[]
self.subjects=[]

def enterMarks(self):
for i in range(3):
sub=input('Enter subject: ')
self.subjects.append(sub)
mark=int(input('Enter marks of %s in %s: '%(self.name,sub)))
self.marks.append(mark)

def total(self):
total=self.marks[0]+self.marks[1]+self.marks[2]
return total

def per(self):
per=(self.marks[0]+self.marks[1]+self.marks[2])/3
return per

def disp(self):
print(self.name,'USN:',self.usn,'got',self.marks,'in',self.subjects)
print('Total marks:',self.total())
print('Percentage:',self.per())

name=input('Enter name of student: ')


usn=input('Enter USN: ')
s1=Student(name,usn)
s1.enterMarks()
s1.disp()

OUTPUT:

Enter name of student: ABHI


Enter USN: 1JS12CS008
Enter subject: MATHS
Enter marks of ABHI in MATHS: 26
Enter subject: CS
Enter marks of ABHI in CS: 48
Enter subject: EC
Enter marks of ABHI in EC: 49
ABHI USN: 1JS12CS008 got [26, 48, 49] in ['MATHS', 'CS', 'EC']
Total marks: 123
Percentage: 41.0

You might also like