1.
STUDENT DETAILS
PROGRAM
print("***********************")
print("Student Details")
name = input("Name: ")
address = input("Address: ")
collegename = input("College Name: ")
coursesubject = input("Course Subject: ")
mobileno = int(input("mobielno:"))
print(" STUDENT DETAILS ")
print(" ************ ")
print("My Name:",name)
print("My Address:",address)
print("My College Name:",collegename)
print("My CourseSubject:",coursesubject)
print("My Mobile no:",mobileno)
print("*************************")
OUTPUT
***********************
Student Details
Name: Suba
Address: No:2,MainRoad,Sathiyamangalam
College Name: Subashakthi College
Course Subject: B.Sc AI & ML
mobielno:6378976552
STUDENT DETAILS
************
My Name: Suba
My Address: No:2,MainRoad,Sathiyamangalam
My College Name: Subashakthi College
My CourseSubject: B.Sc AI & ML
My Mobile no: 6378976552
2.LARGEST THREE NUMBERS
PROGRAM
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))
largest = num1 if (num1 > num2 and num1 > num3) else (num2
if num2 > num3 else num3)
print("The largest number is:", largest)
OUTPUT
Enter the first number: 23
Enter the second number: 34
Enter the third number: 36
The largest number is: 36
3.SUM OF GIVEN NUMBERS
PROGRAM
sum=0
while True:
x=int(input("Enter Positive numbers: "))
if x<0:
print("you enter negative number")
print("End of Series")
break
sum+=x
print("The sum of positive numbers=",sum)
OUTPUT
Enter Positive numbers: 2
Enter Positive numbers: 3
Enter Positive numbers: 4
Enter Positive numbers: 5
Enter Positive numbers: -7
you enter negative number
End of Series
The sum of positive numbers= 14
4.PRODUCT OF TWO MATRICES
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]
print("Product of two matrices")
for r in result:
print(r)
OUTPUT
Product of two matrices
[114, 160, 60, 27]
[74, 97, 73, 14]
[119, 157, 112, 23]
5.GCD OF TWO NUMBERS
PROGRAM
def gcd(a, b):
if a == b:
return a
elif a < b:
return gcd(b, a)
else:
return gcd(b, a - b)
a = int(input("enter 1st value:"))
b = int(input("enter 2nd value:"))
print(gcd(a, b))
OUTPUT
enter 1st value:25
enter 2nd value:40
GCD of Two Numbers 5
6.FACTOTRIAL OF NUMBERS
PROGRAM
def rec_fact(n):
if n == 1:
return n
else:
return n* rec_fact (n-1)
num = int(input("Enter a number: "))
if num< 0:
print("Sorry, factorial does not exist for negative numbers")
elifnum == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of",num,"is", rec_fact (num))
OUTPUT
Enter a number: 5
The factorial of 5 is 120
7.FIBONACCI SEQUENCE
PROGRAM
def rec_fibo(n):
if n <= 1:
return n
else:
return(rec_fibo(n-1) + rec_fibo(n-2))
nterms = 10
if nterms<= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(rec_fibo(i))
OUTPUT
Fibonacci sequence:
0
1
1
2
3
5
8
13
21
34
8. DISPLAY PRIME NUMBER
PROGRAM
def is_prime(n, i=2):
if n <= 2:
return n == 2
if n % i == 0:
return False
if i * i> n:
return True
return is_prime(n, i + 1)
def display_primes(n):
for i in range(2, n + 1):
if is_prime(i):
print(i)
if __name__ == "__main__":
n = int(input("Enter a number: "))
display_primes(n)
OUTPUT:
Enter a number: 30
2
3
5
7
11
13
17
19
23
29
9. SIMPLE CALCULATOR
PROGRAM
def calc(a,b):
sum = a + b
diff = a - b
prod = a * b
quotient = a / b
return sum,diff,prod,quotient
a = int(input("Enter first number:"))
b = int(input("Enter second number:"))
s,d,p,q = calc(a,b)
print("Sum=",s)
print("Difference=",d)
print("Product=",p)
print("Quotient=”,q)
OUTPUT:
>>>
Enter first number:10
Enter second number:5
Sum= 15
Difference= 5
Product= 50
Quotient= 2.0
>>>
SUBASHAKTHI
COLLEGE OF ARTS AND SCIENCE FOR WOMEN
Sathiyamangalam, Kulithalai - 639 120.
B.Sc (ARTIFICIAL INTELLIGENCE & MACHINE LEARNING)
PROGRAMMING IN PYTHON - LAB
Course Code: 22SCCAI2P
Record Note Book –II Semester
Name: ………………………………
Class: ……………………………….
DEPARTMENT OF ARTIFICIAL INTELLIGENCE & MACHINE
LEARNING
2023-2024
SUBASHAKTHI
COLLEGE OF ARTS AND SCIENCE FOR WOMEN
Sathiyamangalam, Kulithalai - 639 120
B.Sc (ARTIFICIAL INTELLIGENCE & MACHINE LEARNING)
PROGRAMMING IN PYTHON - LAB
COURSE CODE: 22SCCAI2P
CERTIFICATE
This is to certify that the bonafide record of work done by
Selvi _______________________ of B.Sc during the academic year 2023-2024
in the Computer Application Laboratory.
Staff-in-Charge Head of the Department
University
Reg.No:
Submitted for the B.sc Major Practical Examination of the
Bharathidasan University, Tiruchirapalli – 620 024 held on _________ at
Subashakthi College of Arts and Science for Women, Kulithalai– 639120.
Examiners
Place: Kulithalai 1.
Date: 2.
INDEX
PAG
S.N SIGNATU
DATE TITLE E
O RE
NO
1 STUDENTS DETAILS
2 LARGEST THREE NUMBERS
3 SUM OF GIVEN NUMBERS
PRODUCT OF TWO
4
MATRICES
5 GCD OF TWO NUMBERS
6 FACTORIAL OF NUMBERS
FIBONACCI SQUENCE OF
7
SERIES
8 DISPLAY PRIME NUMBERS
9 SIMPLE CALCULATOR