0% found this document useful (0 votes)
361 views19 pages

Python Lab Manual

The document provides a laboratory plan for an Introduction to Python Programming course. It includes course objectives, outcomes, teaching-learning process details, programming exercises and evaluation process. The exercises cover topics like reading student details, checking eligibility for senior citizen status, generating Fibonacci sequence, calculating factorial and binomial coefficient, analyzing lists, frequency of digits in numbers, frequent words in text files and complex number operations.

Uploaded by

manyamdwd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
361 views19 pages

Python Lab Manual

The document provides a laboratory plan for an Introduction to Python Programming course. It includes course objectives, outcomes, teaching-learning process details, programming exercises and evaluation process. The exercises cover topics like reading student details, checking eligibility for senior citizen status, generating Fibonacci sequence, calculating factorial and binomial coefficient, analyzing lists, frequency of digits in numbers, frequent words in text files and complex number operations.

Uploaded by

manyamdwd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 19

K. L. E.

SOCIETY’S
K. L. E. INSTITUTE OF TECHNOLOGY,
Opp. Airport, Gokul, Hubballi-580 030
Phone: 0836-2232681 Website:www.kleit.ac.in

Laboratory Plan
Semester: 1 Year: 2022-23

Course Title: Introduction to Python Programming Code: 22PLC15B/25B

Total Hours: 20 Duration of Exam: 3 hrs

Total SEE Marks: 50 Total CIE. Marks: 50

L:T:P:S 2:0:2:0 Credits: 3

Lab. Plan Author: Dr. Shridhar A, Mr. Gurudev S H , Date :

Mrs. Shantha K, Mrs. Suman Y, Mrs. Malathi S Y.

Checked By: Dr. Yeriswamy T Date :

Course objectives
 Learn the syntax and semantics of the Python programming language.
 Illustrate the process of structuring the data using lists, tuples
 Appraise the need for working with various documents like Excel, PDF, Word and
Others.
 Demonstrate the use of built-in functions to navigate the file system.
 Implement the Object Oriented Programming concepts in Python.

Course outcome (Course Skill Set)


 At the end of the course the student will be able to:
 CO1 Demonstrate proficiency in handling loops and creation of functions.
 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.
Teaching-Learning Process
These are sample Strategies, which teacher can use to accelerate the attainment of the various
course outcomes and make Teaching –Learning more effective
1. Use https://pythontutor.com/visualize.html#mode=edit in order to visualize the python
code
2. Demonstrate and visualize basic data types (list, tuple, dictionary).
3. Chalk and talk
4. Online and videos

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 asenior 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 a 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.]
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 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.
Introduction to Python Programming

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.

Input:
Student Details
Enter the Student name: Ramchandra
Enter the Student usn: 2KI22CS005
Enter the Student Marks of Three Subjects
Enter Marks1: 95
Enter Marks2: 68
Enter Marks3: 87

Output
Marks1: 95
Marks2: 68
Marks3: 87
==============================
Total Marks: 250
Percentage: 83.33
==============================

Dept. of CSE Page 1 KLEIT


Introduction to Python Programming

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.

Input:
Enter name of person : Sita
Enter Year of Birth of Sita: 1975

Output
Sita is not a Senior Citizen.
and age of Sita is 48

Dept. of CSE Page 2 KLEIT


Introduction to Python Programming

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


from the console.

Input
How many terms? 6
Output
Fibonacci sequence:
0
1
1
2
3
5

Dept. of CSE Page 3 KLEIT


Introduction to Python Programming

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


compute binomial coefficient (Given N and R).

Input Output
Enter the number:5 Factorial of 5 is 120
Input Output
Enter the Value of n: 10
Enter the Value of r: 5 Binomial Coefficient nCr= 252.0
Dept. of CSE Page 4 KLEIT
Introduction to Python Programming

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

Dept. of CSE Page 5 KLEIT


Introduction to Python Programming

Input
enter the list size 3
enter number at index 0
22
enter number at index 1
33
enter number at index 2
55

Output
user list is [22, 33, 55]
mean of the userlist is 36.666666666666664
variance of the userlist is 188.2222222222222
standard deviation of the userlist 13.719410418171117

Dept. of CSE Page 6 KLEIT


Introduction to Python Programming

4. Read a multi-digit number (as chars) from the console. Develop a


program to print the frequency of each digit with suitable message.

Input
enter the number: 12365478456258

Output
digit frequency
1 1
2 2
3 1
4 2
5 3
6 2
7 1
8 2

Dept. of CSE Page 7 KLEIT


Introduction to Python Programming

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]

Dept. of CSE Page 8 KLEIT


Introduction to Python Programming

Input
Sample.txt

Output
hi 1
welcomw 1
to 1
python 6
programming 6
labthis 1
is 2
labwe 1
are 1
doing 1
6th 1
program 1
3
which 1
will 1
demonstrate 1
file 1
operations 1
in 1
pythonpython 1
this 1
lab 1
The top N value pairs are
{'python': 6, 'programming': 6, '': 3, 'is': 2, 'hi': 1, 'welcomw': 1, 'to': 1, 'labthis':
1, 'labwe': 1, 'are': 1}

Dept. of CSE Page 9 KLEIT


Introduction to Python Programming

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()].

Dept. of CSE Page 10 KLEIT


Introduction to Python Programming

Input
Enter the File to be sorted:
kleit.txt
Enter name of the file to write sorted contents:
cse.txt

Input text file: kleit.txt

output text file:cse.txt

Dept. of CSE Page 11 KLEIT


Introduction to Python Programming

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.

Output
kleit.zip file will be generated in Path: C:\Users\HP\kleit.zip

Dept. of CSE Page 12 KLEIT


Introduction to Python Programming

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.

(Check for all possible inputs)


Input 1
Enter value of x 0
Enter value of y 2
Output 1
Invalid Operation: X must be > 0
None

Input 2
Enter value of x 2
Enter value of y 0
Output 2
Invalid Operation: denominator can't be 0

Input 3
Enter value of x 9
Enter value of y 8
Output 3
Result of x / y is 1.125

Dept. of CSE Page 13 KLEIT


Introduction to Python Programming

9. Define a function which takes TWO objects representing complex


numbers and returns new complex number with a 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.

Input
Enter first complex number
Enter the Real Part: 2
Enter the Imaginary Part: 3
Enter second complex number
Enter the Real Part: 3
Enter the Imaginary Part: 3
Output
........................................................................
First Complex Number: 2+3i
Second Complex Number: 3+3i
Sum of two complex numbers is 5+6i

Dept. of CSE Page 14 KLEIT


Introduction to Python Programming

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.]

Input
Enter name: Neha
Enter USN: 2ki00cs001
Enter marks for subject 1: 60
Enter marks for subject 2: 50
Enter marks for subject 3: 70

Output
Name: Neha
USN: 2ki00cs001
Marks: [60, 50, 70]
Total: 180
Percentage: 60.0 %

Dept. of CSE Page 15 KLEIT

You might also like