0% found this document useful (0 votes)
87 views31 pages

Python Record 1

Uploaded by

dxvxdpaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views31 pages

Python Record 1

Uploaded by

dxvxdpaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNITED COLLEGE OF ARTS AND SCIENCE

Affiliated to Bharathiar Universit , Coimbatore, Periyanaickenpalayam,


Coimbatore – 641 020.

PYTHON PROGRAMMING - LAB

SEMESTER - IV

LABORATORY RECORD

2021 - 2022

DEPARTMENT OF COMPUTERSCIENCE

NAME : ……………………...……………………...

REGISTER NO : ……………………………………………..

CLASS : ……………………………………………..
UNITED COLLEGE OF ARTS AND SCIENCE
Affiliated to Bharathiar University, Coimbatore,Periyanaickenpalayam,
Coimbatore – 641 020.

DEPARTMENT OF COMPUTER SCIENCE

B. Sc. Computer Science with Data Analytics

It is a bonafide record work done by ……………………………………………………………………

Register No. …………………………………………………. during the year ……………………...…

Semester ……………………………. for the ………………………………………………………..…

………………………………. Practical .

Faculty In-Charge Head of the Department

Submitted for the practical examination held on ...................................... at United College of Arts and Science,

Periyanaickenpalayam , Coimbatore 641 020.

Internal Examiner External Examiner


INDEX
Serial
Date Name of the Experiment Page No. Sign
No.

1. Student Details

2. Biggest of Three Number

3. Sum of Series

4. Product of Matricies

GCD Using Recursive


5.
Function

Factorial Using Recursive


6.
Function

Fibonacci Series Using


7.
Recursive Function

Prime Number Using


8.
Recursive Function
Serial
Date Name of the Experiment Page No. Sign
No.

File Operation
9.

Sorting
10.

Calculator
11.

Linear and Binary Search


12.
PYTHON PROGRAMMING - LAB
# List 1 - Student Details #

name = input("Enter Name : ")


full_address =input("Enter full Address : ",)
mobile_number = int(input("Enter Mobile Number : ",))
college_name = input("Enter College Name : ",)
course_subjects = input("Enter Course _subject: ",)
OUTPUT :
Enter Name : Ragu
Enter full Address : 4,Kasthuri palayam road,Coimbatore
Enter Mobile Number : 1234567890
Enter College Name : United College of Arts and Science
Enter Course _subject: Python

RESULT :
Thus the above program has been executed successfully and the
output is verified.
# List 2 - Biggest of Three Number #

a=int(input("Enter a number : "),)


b=int(input("Enter a number : "),)
c=int(input("Enter a number : "),)
if a>b and a>c:
print("A is biggest")
elif b>c:
print("B is biggest")
else:
print("C is biggest")
OUTPUT:

Enter a number : 56
Enter a number : 67
Enter a number : 32
B is biggest

RESULT :
Thus the above program has been executed successfully and the
output is verified.
# List 3 - Sum of Series #

lst=[]
while True:
x=int(input("Numbers:"))
if x>0:
lst.append(x)
if x<0:
print(lst.sort())
print(lst,end="")
print(sum(lst))
break
OUTPUT:
Numbers:45
Numbers:4
Numbers:5
Numbers:-7
None
[4, 5, 45]54

RESULT :
Thus the above program has been executed successfully and the
output is verified.
# List 4 - Product of Matricies #

mxp = [[1, 3],


[6, 2]]

pxr = [[5, 6],


[9, 1]]

res = [[0,0],
[0,0]]

matrix_length = len(mxp)
for i in range(len(mxp)):
for k in range(len(pxr)):
res[i][k] = mxp[i][k] * pxr[i][k]
print("The sum of Matrix mxr and pxr = ",res)
OUTPUT:

The sum of Matrix mxr and pxr = [[5, 18], [54, 2]]

RESULT :
Thus the above program has been executed successfully and the
output is verified.
# List 5 - GCD Using Recursive Function #

def GCD(x,y):
r=x%y
if(r==0):
return y
else:
return GCD(y,r)
n=int(input("Enter the First Number:"))
m=int(input("Enter the Second Number:"))
print("The GCD of Two Numbers is:",GCD(n,m))
OUTPUT :
Enter the First Number:30
Enter the Second Number:45
The GCD of Two Numbers is: 15

RESULT :
Thus the above program has been executed successfully and the
output is verified.
# List 6 - Factorial Using Recursive Function #

def recursive_factorial(n):
if n == 1:
return n
else:
return n*recursive_factorial(n-1)

number=int(input("Enter the Value: "))


if number < 0:
print("Bad Input")
elif number == 0:
print("The Factorial of 0 is 1")
else:
print("The Factorial of",number,"is",recursive_factorial(number))
OUTPUT :

Enter the Value: -2


Bad Input
Enter the Value: 0
The Factorial of 0 is 1
Enter the Value: 8
The Factorial of 8 is 40320

RESULT :
Thus the above program has been executed successfully and the
output is verified.
# List 7 - Fibonacci Series Using Recursive Function #

n=int(input("Numbers:"))
def recur_fibo(n):
if n<=1:
return n
else:
return(recur_fibo(n-1)+recur_fibo(n-2))
nterms=n
if nterms<=0:
print("Please enter a Positive Integer")
else:
print("Fibonacci Sequence:")
for i in range(nterms):
print(recur_fibo(i))
OUTPUT :

Numbers:8
Fibonacci Sequence:
0
1
1
2
3
5
8
13

RESULT :
Thus the above program has been executed successfully and the
output is verified.
# List 8 - Prime Number Using Recursive Function #

def CheckPrime(i,num):
if num==i:
return 0
else:
if(num%i==0):
return 1
else:
return CheckPrime(i+1,num)
n=int(input("Enter the Number:"))
print("Prime Number Between 1 to n are:")
for i in range(2,n+1):
if(CheckPrime(2,i)==0):
print(i,end=" ")
OUTPUT :

Enter the Number:100


Prime Number Between 1 to n are:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79
83 89 97

RESULT :
Thus the above program has been executed successfully and the
output is verified
# List 9 - File Operation #

import random
def file():
n=int(input("enter the count of random numbers to be
stored in a file : "))
outfile=open("random.txt","w")
for i in range(n):
outfile.write(str(random.randint(1,500))+"\n")
outfile.close()
file()
OUTPUT :

Enter the count of random numbers to be stored in a file :10


137

308

479

381

496

142

224

143

402

177

RESULT :
Thus the above program has been executed successfully and the
output is verifie
# List 10 - Sorting #

num1= ["apple","mango","banana","kiwi"]
num1.sort()
print(num1)
num2=[55,23,45,67,78]
num2.sort()
print(num2)
num3=(212,23,25,125)
#sorted(num3)
print(sorted(num3))
OUTPUT :

['apple', 'banana', 'kiwi', 'mango']


[23, 45, 55, 67, 78]
[23, 25, 125, 212]

RESULT :
Thus the above program has been executed successfully and the
output is verified.
# List 11 - Calculator #

def add(x,y):
return x+y
def substract(x,y):
return x-y
def multiply(x,y):
return x*y
def divide(x,y):
return x/y
print("Select Operation")
print("*************************")
print("1.Add")
print("2.Substract")
print("3.Multiply")
print("4.Divide")
while True :
choice=input("Enter your Choice (1/2/3/4) : ")
if choice in('1','2','3','4'):
num1=float(input("Enter the First No : "))
num2=float(input("Enter the Second No : "))
if choice=='1':
print(num1,"+",num2,"=",add(num1,num2))
elif choice=='2':
print(num1,"-",num2,"=",substract(num1,num2))
elif choice=='2':
print(num1,"*",num2,"=",multiply(num1,num2))
elif choice=='2':
print(num1,"/",num2,"=",divide(num1,num2))
next_calculation=input("Lets do next Calculation? (yes/no) :")
if next_calculation=='no':
break
else:
print("Invalid Input")
OUTPUT :
Select Operation :
1.Add
2.Substract
3.Multiply
4.Divide
Enter your Choice (1/2/3/4) : 4
Enter the First No : 5
Enter the Second No : 1
Lets do next Calculation? (yes/no) :yes
Invalid Input
Enter your Choice (1/2/3/4) : 3
Enter the First No : 24545
Enter the Second No : 9090867
Lets do next Calculation? (yes/no) :no

RESULT :
Thus the above program has been executed successfully and the
output is verified.
# List 12 - Linear and Binary Search #

def LinearSearch(array,n,k):
for j in range(0,n):
if (array[j]==k):
return j
return -1
array = [1,3,5,7,9,10,45,34,60,23,44]
print("----------LINEAR SEARCH----------\n\n\n")
print("**************************************")
k=int(input("Enter the Element to be searched:"))
n=len(array)
result=LinearSearch(array,n,k)
if(result==-1):
print("Element not found")
print("\n***********************************")
else:
print("Element found at index:",result)
print("*************************************")
def binarySearch(arr,k,low,high):
while low <= high:
mid=low+(high - low)//22
if arr[mid]==k:
return mid
elif arr[mid]<k:
low=mid+1
else:
high=mid+1
return -1
arr=[1,3,5,7,9]
k=int(input("Enter the Element to be search:"))
result=binarySearch(arr,k,0,len(arr)-1)

if result != -1:
print("Element is present at index"+str(result))
else:
print("Not found")
OUTPUT :
----------LINEAR SEARCH----------
*************************************
Enter the Element to be searched:34
Element found at index: 7
*************************************
Enter the Element to be search:3
Element is present at index1

RESULT :
Thus the above program has been executed successfully and the
output is verified.

You might also like