0% found this document useful (0 votes)
10 views4 pages

Python Record-1 Removed

Uploaded by

MEGHANA BONTHU
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)
10 views4 pages

Python Record-1 Removed

Uploaded by

MEGHANA BONTHU
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
You are on page 1/ 4

VNRVJIET Sheet No: ………..

Name of the Experiment : __________________


Name of the Laboratory :
Python Programming Laboratory Experiment No.___ Date: 22/05/23

Exercise 10 : FUNCTIONS -PROBLEM SOLVING

1. Aim :- To write a function cumulative_product to compute product of a list of numbers.

Code:
def cumulative_product(list1):
p=1
for i in list1:
p=p*i
print(p)
return p
l=[1,2,3,4,5,6,7,8,9,10]
result=cumulative_product(l)
print(result)

OUTPUT:
VNRVJIET Sheet No: ………..
Name of the Experiment : __________________
Name of the Laboratory :
Python Programming Laboratory Experiment No.___ Date: 22/05/23

2. Aim :- To write a function reverse to print the given list in reverse order.

Code :
def reverse(list1):
new=list1[::-1]
return new

l=[1,2,3,4,5,6,7,8,9]
result=reverse(l)
print(result)

OUTPUT:

2. Aim :- To write a function to compute GCD, LCM of two numbers..

Code-1:
import math
gcd=math.gcd(54,24)
print(gcd)
lcm=(54*24)/gcd
print(lcm)

OUTPUT:
VNRVJIET Sheet No: ………..
Name of the Experiment : __________________
Name of the Laboratory :
Python Programming Laboratory Experiment No.___ Date: 22/05/23

Code-2:
def compute_gcd(x,y):
while(y):
x,y=y,x%y
return x
gcd=compute_gcd(54,24)
print(gcd)

OUTPUT:

Code-3:
def gcd(m,n):
if m<n:
(m,n)=(n,m)
if (m%n)==0:
return n
else:
return gcd(n,m%n)
res=gcd(54,24)
print(res)

OUTPUT:
VNRVJIET Sheet No: ………..
Name of the Experiment : __________________
Name of the Laboratory :
Python Programming Laboratory Experiment No.___ Date: 22/05/23

Code-4:
def compute_lcm(x,y):
lcm=(x*y)//compute_gcd(x,y)
return lcm
res=compute_lcm(54,24)
print(res)

OUTPUT:

Code-5:
def compute_lcm1(x,y):
if x>y:
greater=x
else:
greater=y
while(True):
if ((greater%x==0) and (greater%y==0)):
lcm=greater
break
greater=greater+1
return lcm
res=compute_lcm1(54,24)
print(res)

OUTPUT:

You might also like