Programing With Python Lab: Department of Computer Science
Programing With Python Lab: Department of Computer Science
52
2020 - 2021
G.SWETHA
NAME :
18106903
REG. NO :
1
DEPARTMENT OF COMPUTER SCIENCE VISTAS,CHENNAI
SCHOOL OF COMPUTING SCIENCES
DEPARTMENT OF COMPUTER SCIENCE
CERTIFICATE
Certified that this is a bonafide record of practical work done by
Mr./Ms. G.SWETHA . Reg.No. 18106903 in
the B.Sc.,(Computer Science) Laboratory during the Year 2020-2021.
Examiners
DATE : 1.
PLACE : Chennai-600117 2.
December 2020
INDEX
PAGE
S.NO. DATE CONTENTS SIGNATUR
No. E
Printing star pattern
1. 12/8/2020 4
Sum of series of
2. 19/8/2020 numbers 6
Factorial of a number
3. 26/8/2020 8
Checking palindrome
4. 2/9/2020 10
Generating Fibonacci
5. 9/9/2020 12
series
Factors of given
8. 30/9/2020 18
number
Bubble sorting
11. 28/10/2020 24
Aim:-
To write a program that takes a positive integer n and then produces n line of
output shown as follows
PROGRAM CODING:
n=int(input(“enter a number:”))
print(“*”,end=” “)
print(“ “)
OUTPUT :
RESULT:
Hence, this is the Python program executed and output verified successfully .
Ex No:2
19/8/2020 Sum of series of numbers
Aim:-
To write a function that takes an integer “n” as input and calculate the
value of
PROGRAM CODING:
def factorial(n):
fact=1
fact=fact*i
return fact
sum=1
for j in range(1,m+1):
fact1=factorial(j)
sum=sum+(1/fact1)
factorial(int())
OUTPUT :
RESULT:
Hence, this is the Python program executed and output verified successfully.
Ex No:3
26/8/2020 Factorial of a number
Aim:-
To write a function that takes an integer input and calculate the factorial of that
number
PROGRAM CODING:
def factorial(n):
fact=1
for i in range(1,n+1):
fact=fact*i
factorial(int())
OUTPUT :
RESULT:
Hence, this is the Python program executed and output verified
successfully.
Ex No:4
2/9/2020 Checking palindrome
Aim:-
To write a function that takes a string input and check if it’s a
palindrome or not
PROGRAM CODING:
def palindrome(s):
return s==s[::-1]
s=”madam”
ans = palindrome(s)
if ans:
else:
RESULT:
Hence, this is the Python program executed and output verified
successfully.
Ex No:5
9/9/2020 Generating Fibonacci series
Aim:-
To write a program to generate Fibonacci series
PROGRAM CODING:
a=0
b=1
sum=0
count=1
print(“Fibonacci series:”)
while(count<=n):
print(sum)
count+=1
a=b
b=sum
sum=a+b
OUTPUT :
RESULT:
Hence, this is the Python program executed and output verified
successfully.
Ex No:6
PROGRAM CODING:
a=int(input("Enter a value:"))
if (a%2==0):
else:
RESULT:
Hence, this is the Python program executed and output verified successfully.
Ex No:7
PROGRAM CODING:
largest= num1
largest= num2
else:
largest= num3
RESULT:
Hence, this is the Python program executed and output verified
successfully.
Ex No:8
PROGRAM CODING:
def print_factors(X):
if X%i==0
print(i)
num=30
print_factors(num)
OUTPUT :
RESULT:
Hence, this is the Python program executed and output
verified successfully.
Ex No:9
PROGRAM CODING:
def GCD(a,b):
if (b==0):
return a
return GCD(b,a%b)
a=96
b=54
if(GCD(a,b)):
print(“GCD of”,a,”and”,b,”is:”,GCD(a,b))
else:
print(“Not found”)
GCD(a,b)
OUTPUT :
RESULT:
Hence, this is the Python program executed and output verified
successfully.
Ex No:10
PROGRAM CODING:
def search(arr,x):
for i in range(len(arr)):
if arr[i]==x:
return i
return -1
arr=[10,20,80,30,60,50,110,100,130,170]
x = 110
RESULT:
Hence, this is the Python program executed and output verified
successfully.
Ex No:11
28/10/2020 Bubble sorting
Aim:
To write a program to sort a list using bubble sort.
PROGRAM CODING:
Numlist=[5,100,12,40,13,20]
Number=len(Numlist)
for i in range(1,Number+1):
for j in range(i+1,Number):
temp=Numlist[i]
Numlist[i]=Numlist[j]
Numlist[j]=temp
Print(Numlist)
OUTPUT:
RESULT:
Hence, this is the Python program executed and output verified
successfully.
Ex No:12
Aim:
To write a program to multiply two matrices .
PROGRAM CODING:
X=[[3,4],
[4,5]]
Y=[[5,1],
[6,3]]
result=[[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:
RESULT:
Hence, this is the Python program executed and output verified
successfully.