PROGRAMING WITH PYTHON 18PBCS52
52
SCHOOL OF COMPUTING SCIENCES
DEPARTMENT OF COMPUTER SCIENCE
PROGRAMING WITH PYTHON LAB
RECORD NOTE BOOK
2020 - 2021
B.Sc., Computer Science
Third Year – V Semester
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.
STAFF IN-CHARGE HEAD OF THE DEPARTMENT
Submitted for B.Sc., Degree practical examination held on
in the Department of Computer Science at VISTAS.
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
Checking even or odd
6. 16/9/2020 14
Largest of three
Numbers
7. 23/9/2020 16
Factors of given
8. 30/9/2020 18
number
GCD of two numbers
9. 7/10/2020 20
Linear search on list
10. 14/10/2020 22
Bubble sorting
11. 28/10/2020 24
Multiplying two Matrices
12. 11/11/2020 26
Ex No:1
12/8/2020 Printing star pattern
Aim:-
To write a program that takes a positive integer n and then produces n line of
output shown as follows
For example enter a size : 5
*
**
***
****
*****
PROGRAM CODING:
n=int(input(“enter a number:”))
for row in range(1,n+1):
for column in range(1,row+1):
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
1+1/1! + 1/2! + 1/3!....+1/n!
PROGRAM CODING:
def factorial(n):
fact=1
for i in range (1,n+1):
fact=fact*i
return fact
sum=1
m=int(input(“enter the final value:”))
for j in range(1,m+1):
fact1=factorial(j)
sum=sum+(1/fact1)
print(“The factorial value is:”,sum)
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):
num = int(input("Enter a n value: "))
fact=1
for i in range(1,n+1):
fact=fact*i
print(“The factorial value of”,n,”is”,fact)
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:
print("given string is a palindrome... ")
else:
print("given string is not a palindrome...")
OUTPUT :
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:
n=int(input("enter a value of n:"))
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
16/9/2020 Checking Even or odd
Aim:-
To write a program to check whether the input number is even or odd
PROGRAM CODING:
a=int(input("Enter a value:"))
if (a%2==0):
print("this number is even number")
else:
print("The number is odd number")
OUTPUT :
RESULT:
Hence, this is the Python program executed and output verified successfully.
Ex No:7
23/9/2020 Largest of three numbers
Aim:-
To write a program to compare three number and print largest one
PROGRAM CODING:
num1 = int(input("Enter a 1st number: "))
num2 = int(input("Enter a 2nd number: "))
num3 = int(input("Enter a 3rd number: "))
if (num1 > num2) and (num1 > num3):
largest= num1
elif (num2 > num3):
largest= num2
else:
largest= num3
print("The largest number is",largest)
OUTPUT :
RESULT:
Hence, this is the Python program executed and output verified
successfully.
Ex No:8
30/9/2020 Factors of given number
Aim:-
To write a program to print a factors of a given number.
PROGRAM CODING:
def print_factors(X):
print("The factors of”,X.”are:")
for i in range (1,X+1):
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
7/10/2020 GCD of two numbers
Aim:
To write a method to calculate GCD of two numbers.
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
14/10/2020 Linear search on list
Aim:
To write a program to implement linear search on list.
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
print("element found at index "+str(search(arr,x)))
OUTPUT:
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):
if (Numlist[i] > Numlist[j]):
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
11/11/2020 Multiplying two Matrices
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.