Lab 6

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

IU1641050062 Vidhi Parekh

LAB 6
Practical 1:
WAPP with recursive function

Source Code

def fact(x):
if x == 1:
return 1
else:
return (x * fact(x-1))

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


print(fact(number))

Output

Enter the number: 5


120

Practical 2:
WAPP to use function as object

Source Code

def factR(x):
if x == 1:
return 1
else:
return (x * factR(x-1))

def funasobj(l,func):
for i in range(len(l)):
l[i] = func(l[i])
print(l)

funasobj ([4,-5,-6,3,-98],abs)
funasobj ([1.6,7,5.3,8.2,4],int)
funasobj ([1,5,3,2],factR)

pg. 1
IU1641050062 Vidhi Parekh

Output

[4, 5, 6, 3, 98]
[1, 7, 5, 8, 4]
[1, 120, 6, 2]

Practical 3:
WAPP to demonstrate the use of lambda expression

Source Code

z = list(map(lambda x,y : x**y,[1,2,3,4],[3,2,1,0]))


print(z)

Output

[1, 4, 3, 1]

Practical 4:
WAPP demonstrate function scope

Source Code

def outer_func():
a = 20
def inner_func():
a = 30
print('a = ', a)
inner_func()
print('a = ',a)

a = 10
outer_func()
print('a = ',a)

Output

a = 30
a = 20
a = 10

pg. 2

You might also like