JAMAL MOHAMED COLLEGE (Autonomous)
Accredited with A++ Grade by NAAC (4th Cycle) with CGPA 3.69 out of 4.0
(Affiliated to Bharathidasan University)
Tiruchirappalli – 620 020
PG and Research Department of Mathematics
Bachelor of Science
I. B. Sc (Mathematics)
Record Note Book
2023-2024
SEMESTER - II
Python Programming Practical ( 23UMA2CC3P )
Name:
Roll Number:
Register Number:
JAMAL MOHAMED COLLEGE (Autonomous)
Accredited with A++ Grade by NAAC (4th Cycle) with CGPA 3.69 out of 4.0
(Affiliated to Bharathidasan University)
Tiruchirappalli – 620 020
PG and Research Department of Mathematics
Bachelor of Science
Semester – II
Python Programming Practical ( 23UMA2CC3P )
CERTIFICATE
Name :
Roll Number : Register Number :
This is to certify that this is the bonafide record of practical work done in the computer
lab of Jamal Mohamed College, Tiruchirappalli during the academic year 2023 – 2024.
Staff in-charge Head of the Department
Submitted for the Bachelor of Science Practical Examination held at Jamal Mohamed
College, Tiruchirappalli – 620 020, on 13-03-2024.
Examiners:-
Date :- 13-03-2024 1.
Place :- Tiruchirappalli.
2.
CONTENTS
[Link] Date Exercise Page Signature
No
1. 24.11.2023 SIMPLE EXPRESSIONS 1
2. 24.11.2023 SQUARE ROOT 3
3. 27.11.2023 AREA OF TRIANGLE 5
4. 27.11.2023 SOLVE QUADRATIC EQUATION 7
5. 01.12.2023 SWAP TWO VARIABLES 9
6. 11.12.2023 ODD OR EVEN 11
7. 11.12.2023 LARGEST AMONG THREE NUMBERS 13
8. 13.12.2023 FACTORIAL OF A GIVEN NUMBER 15
9. 20.12.2023 FIBONACCI SEQUENCE 17
10. 20.12.2023 SUM OF NATURAL NUMBER 19
11. 03.01.2024 FACTORS OF A GIVEN NUMBER 21
12. 03.01.2024 H.C.F AND L.C.M 23
13. 08.01.2024 NUMBER SYSTEM CONVERSION 26
14. 10.01.2024 SORTING STRING 28
15. 10.01.2024 PALINDROME 30
16. 19.01.2024 RANDOM NUMBER 32
17. 19.01.2024 TEMPERATURE CONVERTION 34
18. 22.01.2024 SUM OF THE INDIVIDUAL DIGITS 36
19. 22.01.2024 H.C.F OF TWO NUMBERS 38
20. 29.01.2024 ACCESS ELEMENTS USING INDEX 41
21. 29.01.2024 CHANGE LIST ITEMS 43
22. 07.02.2024 INSERT ELEMENTS IN THE LIST 45
23. 07.02.2024 APPEND AN ELEMENT IN LIST 47
24. 13.02.2024 REMOVE ELEMENT IN LIST 49
25. 15.02.2024 MATRIX MULTIPLICATIONS 51
26. 22.02.2024 CREATE A PYTHON TUPLE 53
27. 28.02.2024 COUNT ELEMENTS IN THE TUPLE 55
28. 28.02.2024 TUPLE INDEX 57
Exercise No: 1
Date: 24.11.2023 SIMPLE EXPRESSIONS
AIM:
Python Program to Evaluate the Arithmetic Expressions.
ALGORITHM:
1
PROGRAM:
x = 40
y = 12
add = x +
y sub = x -
y pro = x *
y div = x /
print(add)
print(sub)
print(pro)
print(div)
OUTPUT:
52
28
480
3.3333333333333335
2
Exercise No: 2
Date: 24.11.2023 SQUARE ROOT
AIM:
Python Program to calculate the square root
ALGORITHM:
3
PROGRAM:
num = float(input('Enter a number:'))
num_sqrt = num **(1/2)
print('The square root of %0.4f is %0.4f'%(num,num_sqrt))
OUTPUT:
Enter a number:25
The square root of 25.0000 is 2.9240
4
Exercise No: 3 AREA OF TRIANGLE
Date: 27.11.2023
AIM:
Python Program to calculate the Area of Triangle
ALGORITHM:
5
PROGRAM:
a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: ')) s = (a + b
+ c) / 2
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)
OUTPUT:
Enter first side: 6
Enter second side: 9
Enter third side: 8
The area of the triangle is 23.53
6
Exercise No: 4 SOLVE QUADRATIC EQUATION
Date: 27.11.2023
AIM:
Python Program to Solve Quadratic Equation.
ALGORITHM:
7
PROGRAM:
import cmath
a = int(input("enter the value of a:"))
b = int(input("enter the value of b:"))
c = int(input("enter the value of c:"))
d = (b**2) - (4*a*c)
sol1 = (-[Link](d))/(2*a) sol2
= (-b+[Link](d))/(2*a)
print('The solution are {0} and {1}'.format(sol1,sol2))
OUTPUT:
enter the value of a:1
enter the value of
b:4 enter the value
of c:4
The solution are (-2+0j) and (-2+0j)
8
Exercise No: 5 SWAP TWO VARIABLES
Date: 01.12.2023
AIM:
Python Program to Swap Two Variables
ALGORITHM:
9
PROGRAM:
x = int(input('Enter value of x: ')) y
= int(input('Enter value of y: '))
temp=x x=y y=temp print('The value of x after
swapping: {}'.format(x)) print('The value of y
after swapping: {}'.format(y))
OUTPUT:
Enter value of x: 10
Enter value of y: 20
The value of x after swapping: 20
The value of y after swapping: 10
10
Exercise No: 6 ODD OR EVEN
Date: 11.12.2023
AIM:
Python Program to Check the given Number is Odd or Even.
ALGORITHM:
11
PROGRAM:
# Python program to check if the input number is odd or
even.
# If the remainder is 1, it is an odd number.
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
OUTPUT:
Enter a number: 9
9 is Odd
Enter a number: 18
18 is Even
12
Exercise No: 7 LARGEST AMONG THREE NUMBERS
Date: 11.12.2023
AIM:
Python Program to Find Largest among Three Numbers.
ALGORITHM:
13
PROGRAM:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number:
")) num3 = float(input("Enter third number:
")) if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
OUTPUT:
Enter first number: 20
Enter second number: 07
Enter third number: 05
The largest number is 20.0
14
Exercise No: 8 FACTORIAL OF A GIVEN NUMBER
Date: 13.12.2023
AIM:
Python Program to Find the Factorial of a given Number.
ALGORITHM:
15
PROGRAM:
num = int(input("Enter a number: "))
factorial = 1
# check if the number is negative, positive or zero if num <
0: print("Sorry, factorial does not exist for negative
numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
OUTPUT:
Enter a number: 7
The factorial of 7 is 5040
16
Exercise No: 9 FIBONACCI SEQUENCE
Date: 20.12.2023
AIM:
Python Program to Print Fibonacci Sequence up to n Terms.
ALGORITHM:
17
PROGRAM:
n = int(input("How many terms?
")) n1,n2 = 0,1 print("Fibonacci
sequence:") print (n1)
print (n2)
for i in range
(3,n+1): n3 = n1 +
n2 print(n3) n1 = n2
n2 = n3
OUTPUT:
How many terms? 5
Fibonacci sequence:
18
Exercise No: 10 SUM OF NATURAL NUMBER
Date: 20.12.2023
AIM:
Python Program to Find the Sum of Natural Numbers.
ALGORITHM:
19
PROGRAM:
num = int(input("Enter the
number:")) if num < 0: print("Enter a
positive number") else:
sum = 0
while(num >
0): sum +=
num num -=
print("The sum is", sum)
OUTPUT:
Enter the number: 16
The sum is 136
20
Exercise No: 11 FACTORS OF A GIVEN NUMBER
Date: 03.01.2024
AIM:
Python Program to Find Factors of a Given Number.
ALGORITHM:
21
PROGRAM:
def print_factors(x): print("The
factors of",x,"are:") for i in
range(1, x + 1):
if x % i == 0:
print(i)
num = 10
print_factors(num)
OUTPUT:
The factors of 10 are:
1
2
5
10
22
Exercise No: 12 H.C.F AND L.C.M
Date: 03.01.2024
AIM:
Python Program to Find H.C.F and L.C.M
ALGORITHM:
23
PROGRAM:
def hcf(x, y):
if x > y:
smaller = y
else:
smaller = x
print("Common factors:")
for i in range(1,
smaller+1):
if((x % i == 0) and (y % i == 0)):
hcf = i print(hcf) return hcf
num1=int(input("Enter first num:"))
num2=int(input("Enter second num:")) print("The
H.C.F. is", hcf(num1, num2)) print("The L.C.M. is",
(num1*num2)/hcf(num1,num2))
24
OUTPUT:
Enter first num:24
Enter second num:36
Common factors:
12
The H.C.F. is 12
Common factors:
12
The L.C.M. is 72.0
25
26
PROGRAM:
Exercise No: 13 NUMBER SYSTEM CONVERSION
Date: 08.01.2024
AIM:
Python Program to Convert Decimal into Other Number System.
ALGORITHM:
27
dec=int(input('Enter number:'))
print("The decimal value of", dec,
"is:") print(bin(dec), "in binary.")
print(oct(dec), "in octal.")
print(hex(dec), "in hexadecimal.")
OUTPUT:
Enter number: 24
The decimal value of 24 is:
0b11000 in binary.
0o30 in octal.
0x18 in hexadecimal.
28
PROGRAM:
Exercise No: 14 SORTING STRING
Date: 10.01.2024
AIM:
Python Program to Sort Words in Alphabetical Order.
ALGORITHM:
29
mystr = input("Enter a string: ")
words = [[Link]() for word in
[Link]()] [Link]() print("The sorted
words are:") for word in words:
print(word)
OUTPUT:
Enter a string: HARI PRASANNA VISHWADHARSHAN RAVI RAHMAN
The sorted words are:
hari
prasanna
rahman
ravi
vishwadharsan
30
PROGRAM:
Exercise No: 15 PALINDROME
Date: 10.01.2024
AIM:
Python Program to check the given string is palindrome.
ALGORITHM:
31
name=str(input('Enter string:'))
name= [Link]()
rev= reversed(name)
if list(name) == list(rev):
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
OUTPUT:
Enter string:MOM
The string is a palindrome.
Enter string:HAHA
The string is not a palindrome.
32
PROGRAM:
Exercise No: 16 RANDOM NUMBER
Date: 19.01.2024
AIM:
Python Program to generate a random number.
ALGORITHM:
33
import random
for i in range (1,11):
print("student-",i,"random number-",[Link](0,1000))
OUTPUT:
student- 1 random number- 43
student- 2 random number- 685
student- 3 random number- 970
student- 4 random number- 233
student- 5 random number- 419
student- 6 random number- 986
student- 7 random number- 220
student- 8 random number- 426
student- 9 random number- 560
student- 10 random number- 697
34
PROGRAM:
Exercise No: 17 TEMPERATURE CONVERTION
Date: 19.01.2024
AIM:
Python Program to convert temperature Celsius to Fahrenheit.
ALGORITHM:
35
PROGRAM:
Celsius=float(input("Enter Celsius:"))
Fahrenheit = (Celsius*1.8)+32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(Celsius, Fahrenheit))
OUTPUT:
Enter celsius38
38.0 degree Celsius is equal to 100.4 degree Fahrenheit
36
37
Exercise No: 18 SUM OF THE INDIVIDUAL DIGITS
Date: 22.01.2024
AIM:
Python Program to Find the Sum of the Individual Digits.
ALGORITHM:
38
PROGRAM:
n=int(input('Enter number:'))
s=0
while(n!=0):
d=n%10
s=s+d
n=n//10
print("The sum of the digits is:",s)
OUTPUT:
Enter number:457896356585456
The sum of the digits is: 86
39
Exercise No: 19 H.C.F OF TWO NUMBERS
Date: 22.01.2024
AIM:
Python Program to find H.C.F of two numbers.
ALGORITHM:
40
PROGRAM:
def hcf(x, y):
if x > y:
smaller = y
else:
smaller = x
print("Common factors:")
for i in range(1,
smaller+1):
if((x % i == 0) and (y % i == 0)):
hcf = i print(hcf) return hcf
num1=int(input("Enter first num:"))
num2=int(input("Enter second num:"))
print("The H.C.F. is", hcf(num1,
num2))
41
OUTPUT:
Enter first num: 24
Enter second num: 36
Common factors:
12
The H.C.F. is 12
42
43
PROGRAM:
Exercise No: 20 ACCESS ELEMENTS USING INDEX
Date: 29.01.2024
AIM:
Python Program to Access Elements Using Index in List.
ALGORITHM:
44
languages = ['Python', 'Swift', 'C++']
print(languages[0])
print(languages[1])
print(languages[2])
OUTPUT:
Python
Swift
C++
45
PROGRAM:
Exercise No: 21 CHANGE LIST ITEMS
Date: 29.01.2024
AIM:
Python Program to Change List Items.
ALGORITHM:
46
colours = ['Red', 'Black',
'Green'] print('Original List:',
colours) colours[2] = 'Blue'
print('Updated List:', colours)
OUTPUT:
Original List: ['Red', 'Black', 'Green']
Updated List: ['Red', 'Black', 'Blue']
47
PROGRAM:
Exercise No: 22 INSERT ELEMENTS IN THE LIST
Date: 07.02.2024
AIM:
Python Program to insert elements in the list.
ALGORITHM:
48
vowel = ['a', 'e',
'i','u']
[Link](3, 'o')
print('List:', vowel)
OUTPUT:
List: ['a', 'e', 'i', 'o', 'u']
49
PROGRAM:
50
Exercise No: 23 APPEND AN ELEMENT IN LIST
Date: 07.02.2024
AIM:
Python Program to append an element in list.
ALGORITHM:
51
PROGRAM:
animals = ['cat', 'dog', 'rabbit']
[Link]('cow')
print('Updated animals list: ', animals)
OUTPUT:
Updated animals list: ['cat', 'dog', 'rabbit', 'cow']
52
53
PROGRAM:
Exercise No: 24 REMOVE ELEMENT IN LIST
Date: 13.02.2024
AIM:
Python Program to remove element in the list.
ALGORITHM:
54
animals = ['cat', 'dog', 'rabbit', 'guinea pig']
[Link]('dog')
print('Updated animals list: ', animals)
OUTPUT:
Updated animals list: ['cat', 'rabbit', 'guinea pig']
55
PROGRAM:
56
Exercise No: 25 MATRIX MULTIPLICATIONS
Date: 15.02.2024
AIM:
Python Program to multiply two matrix.
ALGORITHM:
57
PROGRAM:
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[5,8,1,2],
[6,7,3,0],
[4,5,9,1]]
result = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print(r)
OUTPUT:
[114, 160, 60, 27]
[74, 97, 73, 14]
[119, 157, 112, 23]
58
Exercise No: 26 CREATE A PYTHON TUPLE
Date: 22.02.2024
AIM:
Python Program to Create Python Tuple.
ALGORITHM:
59
PROGRAM:
numbers = (1, 2, -5)
print(numbers)
OUTPUT:
Output: (1, 2, -5)
60
Exercise No: 27 COUNT ELEMENTS IN THE TUPLE
Date: 28.02.2024
AIM:
Python Program to count elements in the tuple.
ALGORITHM:
61
PROGRAM:
numbers = (1, 2, -5)
print(numbers)
OUTPUT:
Output: (1, 2, -5)
62
63
PROGRAM:
Exercise No: 28 TUPLE INDEX
Date: 28.02.2024
AIM:
Python Program to find index of the given element in tuple.
ALGORITHM:
64
vowels = ('a', 'e', 'i', 'o',
'u') index =
[Link]('e')
print(index)
OUTPUT:
65