lOMoARcPSD|44417779
Programming in Python Laboratory Manual
Programming in Python (I. K. Gujral Punjab Technical University)
Scan to open on Studocu
Studocu is not sponsored or endorsed by any college or university
Downloaded by Ishika ishika (
[email protected])
lOMoARcPSD|44417779
Programming in Python Laboratory
(UGCA1917)
LABORATORY MANUAL
BCA
II Year – IIIrd Semester
(2021-2022)
By: Dr. Gagandeep Kaur
Department of Computer Applications
Chandigarh School of Business
Chandigarh Group of Colleges
(Jhanjeri, Mohali)
lOMoARcPSD|44417779
Table of Contents
S.No Practical Name Page No.
1. Compute sum, subtraction, multiplication, division and exponent of 3
given variables input by the user.
2. Compute area of following shapes: circle, rectangle, triangle, 4
square, trapezoid and parallelogram
3. Compute volume of following 3D shapes: cube, cylinder, cone and 6
sphere
4. Compute and print roots of quadratic equation ax2+bx+c=0, where 8
the values of a, b, and c are input by the user.
5. Print numbers up to N which are not divisible by 3, 6, 9,, e.g., 1, 2, 9
4, 5, 7,….
6. Write a program to determine whether a triangle is isosceles or not? 10
7. Print multiplication table of a number input by the user 11
8. Compute sum of natural numbers from one to n number 12
9. Print Fibonacci series up to n numbers e.g. 0 1 1 2 3 5 8 13…..n 13
10. Compute factorial of a given number 14
11. Count occurrence of a digit 5 in a given integer number input by the 15
user
12. Print Geometric and Harmonic means of a series input by the user 16
13. Evaluate the following expressions: 17
a. x-x2/2!+x3/3!- x4/4!+… xn/n!
b. x-x3/3!+x5/5!- x7/7!+… xn/n!
14. Print all possible combinations of 4, 5, and 6. 19
15. Determine prime numbers within a specific range 20
16. Count number of persons of age above 60 and below 90. 21
17. Compute transpose of a matrix 22
18. Perform following operations on two matrices. 24
1) Addition 2) Subtraction 3) Multiplication
19. Count occurrence of vowels. 26
20. Count total number of vowels in a word 27
21. Determine whether a string is palindrome or not 28
22. Perform following operations on a list of numbers: 29
1) Insert an element 2) delete an element 3) sort the list 4) delete
entire list
lOMoARcPSD|44417779
23. Display word after Sorting in alphabetical order 31
24. Perform sequential search on a list of given numbers 32
25. Perform sequential search on ordered list of given numbers 33
26. Maintain practical note book as per their serial numbers in library 34
using Python dictionary
27. Perform following operations on dictionary 35
1) Insert 2) delete 3) change
28. Check whether a number is in a given range using functions. 36
29. Write a Python function that accepts a string and calculates number 37
of upper case letters and lower case letters available in that string
30. To find the Max of three numbers using functions 38
31. Multiply all the numbers in a list using functions 39
32. Solve the Fibonacci sequence using recursion 40
33. Get the factorial of a non-negative integer using recursion 41
34. Write a program to create a module of factorial in Python 42
35. Design a Python class named Rectangle, constructed by a length & 43
width, also design a method which will compute the area of a
rectangle
36. Design a Python class named Circle constructed by a radius and two 44
methods which will compute the area and the perimeter of a circle
37. Design a Python class to reverse a string ‘word by word’ 45
38. Write a Python program to read an entire text file. 46
39. Design a Python program to read first n lines of a text file. 47
40. Construct a Python program to write and append text to a file and 48
display the text.
lOMoARcPSD|44417779
Practical-1
Compute sum, subtraction, multiplication, division and exponent of given variables input
by the user
Output:
lOMoARcPSD|44417779
Practical-2
Compute area of following shapes: circle, rectangle, triangle, square, trapezoid and parallelogram
lOMoARcPSD|44417779
Output:
lOMoARcPSD|44417779
Practical-3
Compute volume of following 3D shapes: cube, cylinder, cone and sphere
lOMoARcPSD|44417779
Output:
lOMoARcPSD|44417779
Practical-4
Compute and print roots of quadratic equation ax2+bx+c=0, where the values of a, b, and c
are input by the user
Output:
lOMoARcPSD|44417779
Practical-5
Print numbers up to N which are not divisible by 3, 6, 9,, e.g., 1, 2, 4, 5, 7,….
lOMoARcPSD|44417779
Practical-6
Write a program to determine whether a triangle is isosceles or not?
10
lOMoARcPSD|44417779
Practical – 7
Print multiplication table of a number input by the user
Output:
11
lOMoARcPSD|44417779
Practical – 8
Compute sum of natural numbers from one to n number
Output:
12
lOMoARcPSD|44417779
Practical-9
Print Fibonacci series up to n numbers e.g. 0 1 1 2 3 5 8 13…..n
Output:
13
lOMoARcPSD|44417779
Practical—10
Compute factorial of a given number
Output:
14
lOMoARcPSD|44417779
Practical—11
Count occurrence of a digit 5 in a given integer number input by the user
Output:
15
lOMoARcPSD|44417779
Practical—12
Print Geometric and Harmonic means of a series input by the user
Output:
16
lOMoARcPSD|44417779
Practical—13
Evaluate the following expressions:
a. x-x2/2!+x3/3!- x4/4!+… xn/n!
b. x-x3/3!+x5/5!- x7/7!+… xn/n!
a. x-x2/2!+x3/3!- x4/4!+… xn/n!
Output:
17
lOMoARcPSD|44417779
b. x-x3/3!+x5/5!- x7/7!+… xn/n!
Output:
18
lOMoARcPSD|44417779
Practical—14
Print all possible combinations of 4, 5, and 6.
Output:
19
lOMoARcPSD|44417779
Practical –15
Determine prime numbers within a specific range
Output:
20
lOMoARcPSD|44417779
Practical—16
Count number of persons of age above 60 and below 90.
Output:
21
lOMoARcPSD|44417779
Practical—17
Compute transpose of a matrix
22
lOMoARcPSD|44417779
Output:
23
lOMoARcPSD|44417779
Practical—18
Perform following operations on two matrices.
1) Addition
2) Subtraction
3) Multiplication
Output:
Output:
24
lOMoARcPSD|44417779
Output:
25
lOMoARcPSD|44417779
Practical—19
Count occurrence of vowels.
Output:
26
lOMoARcPSD|44417779
Practical—20
Count total number of vowels in a word
Output:
27
lOMoARcPSD|44417779
Practical—21
Determine whether a string is palindrome or not
Output:
28
lOMoARcPSD|44417779
Practical—22
Perform following operations on a list of numbers:
1) Insert an element
2) delete an element
3) sort the list
4) delete entire list
29
lOMoARcPSD|44417779
Output:
30
lOMoARcPSD|44417779
Practical –23
Display word after Sorting in alphabetical order
Output:
31
lOMoARcPSD|44417779
Practical –24
Perform sequential search on a list of given numbers
Output:
32
lOMoARcPSD|44417779
Practical—25
Perform sequential search on ordered list of given numbers
Output:
33
lOMoARcPSD|44417779
Practical –26
Maintain practical note book as per their serial numbers in library using Python dictionary
Output:
34
lOMoARcPSD|44417779
Practical—27
Perform following operations on dictionary
1) Insert
2) delete
3) change
Ouptut:
35
lOMoARcPSD|44417779
Practical—28
Check whether a number is in a given range using functions.
Output:
36
lOMoARcPSD|44417779
Practical—29
Write a Python function that accepts a string and calculates number of upper case letters and
lower case letters available in that string
Output:
37
lOMoARcPSD|44417779
Practical—30
To find the Max of three numbers using functions
Output:
38
lOMoARcPSD|44417779
Practical—31
Multiply all the numbers in a list using functions
Output:
39
lOMoARcPSD|44417779
Practical—32
Solve the Fibonacci sequence using recursion
Output:
40
lOMoARcPSD|44417779
Practical—33
Get the factorial of a non-negative integer using recursion
Output:
41
lOMoARcPSD|44417779
Practical—34
Write a program to create a module of factorial in Python
Output
42
lOMoARcPSD|44417779
Practical—35
Design a Python class named Rectangle, constructed by a length & width, also design a method
which will compute the area of a rectangle
Output
43
lOMoARcPSD|44417779
Practical—36
Design a Python class named Circle constructed by a radius and two methods which will compute
the area and the perimeter of a circle
Output
44
lOMoARcPSD|44417779
Practical – 37
Design a Python class to reverse a string ‘word by word’
Output
45
lOMoARcPSD|44417779
Practical –38
Write a Python program to read an entire text file.
Contents of test.txt
A pattern can be defined as anything that follows a trend and exhibits some kind of regularity. The
recognition of patterns can be done physically, mathematically or by the use of algorithms.
Output
46
lOMoARcPSD|44417779
Practical—39
Design a Python program to read first n lines of a text file.
Contents of test.txt
Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.
A pattern can be defined as anything that follows a trend and exhibits some kind of regularity.
The recognition of patterns can be done physically, mathematically or by the use of algorithms.
Output
47
lOMoARcPSD|44417779
Practical—40
Construct a Python program to write and append text to a file and display the text.
Output
48