0% found this document useful (0 votes)
8 views3 pages

Functions in Python - 241216 - 093710

This the pdf of python code. Use it and do practice.

Uploaded by

sumitkrr78
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)
8 views3 pages

Functions in Python - 241216 - 093710

This the pdf of python code. Use it and do practice.

Uploaded by

sumitkrr78
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/ 3

g8o1o953o

December 3, 2024

[1]: # What is a function in python programming

[3]: # wap to add two values using function


def add(a,b):

return a+b
add(8,9)

[3]: 17

[5]: def add(a,b):


result=a+b
print("the addition of a and b =",result)
a=int(input("enter the value of a "))
b=int(input("enter the value of b "))
add(a,b)

enter the value of a 6


enter the value of b 8
the addition of a and b = 14

[7]: def comparison(a,b):


if(a>b):
print("a is grrater")
else:
print("b is greater ")
a=int(input("enter the value of a "))
b=int(input("enter the value of b "))
comparison(a,b)

enter the value of a 3


enter the value of b 4
b is greater

[15]: def even_odd(a):


if a%2==0:
print("number is even")

1
else:
print("number is odd")
a=int(input("enter any number"))
even_odd(a)

enter any number 56


number is even

[21]: # wap to find the factorial of any number using functions

def factorial(number):
fact=1
while(number>0):
fact*=number
number-=1
print("the factorial of number is ",fact)
number=int(input("enter any number"))
factorial(number)

enter any number 5


the factorial of number is 120

[29]: # wap to print fibonacci series upto N limit


def fibonacci(number):
a=0
b=1
limit=1
while(limit<=number):
print(a,end=" ")
a,b=b,a+b
limit+=1
number=int(input("enter the limit of your fibonacci series "))
fibonacci(number)

enter the limit of your fibonacci series 10


0 1 1 2 3 5 8 13 21 34

[31]: # lambda function is a special anonymous function which is define by lambda␣


↪keyword. It is a one liner function

add=lambda x,y:x+y
x=int(input("enter the value of x "))
y=int(input("enter the value of y "))
print("the addition of x and y is ",add(x,y))

enter the value of x 5


enter the value of y 7

2
the addition of x and y is 12

[33]: # wap to print even numbers form the given list using lambda function
number=[432,2,432,12,343,23,4,55,66,5,67777,88,90989,87,787,678,876]
even=list(filter(lambda x:x%2==0,number))
print("the even numbers are :",even)

the even numbers are : [432, 2, 432, 12, 4, 66, 88, 678, 876]

[37]: # wap to print odd numbers form the given list using lambda function
number=[432,2,432,12,343,23,4,55,66,5,67777,88,90989,87,787,678,876]
odd=list(filter(lambda x:x%2!=0,number))
print("the odd numbers are :",odd)

the odd numbers are : [343, 23, 55, 5, 67777, 90989, 87, 787]

[ ]:

You might also like