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

Function

The document outlines various practical examples of Python functions, including those with and without arguments, and functions that return values. It also covers built-in date, math, and random functions. Each practical example demonstrates a specific functionality, such as checking if a number is even or performing basic arithmetic operations.

Uploaded by

nikhilmak22
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)
3 views3 pages

Function

The document outlines various practical examples of Python functions, including those with and without arguments, and functions that return values. It also covers built-in date, math, and random functions. Each practical example demonstrates a specific functionality, such as checking if a number is even or performing basic arithmetic operations.

Uploaded by

nikhilmak22
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

Functions

Practical 1: function without arguments:


def smsprint():
print("Welcome to python function")
print("++++++++++++++++++++++++++")
print("This is demo program")
print("end of Programs")

Practical 2: function with arguments:


def welcome(name):
print("Hello",name)

Practical 3: function without arguments:


def is_even():
x=int(input("Enter number"))
if (x%2==0):
print("Entered number is Even")
else:
print("Entered number is Odd")

Practical 4: function with arguments:


def is_even(num):
if (num%2==0):
print("Entered number is Even")
else:
print("Entered number is Odd")

Practical 5: function with arguments:


def calc(a,b):
add=a+b
sub=a-b
div=a/b
mul=a*b
print("Addition:",add)
print("subtraction:",sub)
print("division:",div)
print("Multiplication:",mul)

Practical 6: function with arguments with single return:


def sum(a,b):
c=a+b
return c
result=sum(10,50)
print("Sum:",result)

1
print("Sum:",sum(10,10))

Practical 7: function with arguments with multiple returns:


def calc(x,y):
a=x+y
b=x-y
c=x*y
d=x/y
return a,b,c,d

add,sub,mul,div=calc(20,10)
print("Sum:",add)
print("Subtraction:",sub)
print("multiplication:",mul)
print("Division:",div)

Practical 8: function with default arguments and with multiple returns:

def calc(x,y=20):
a=x+y
b=x-y
c=x*y
d=x/y
return a,b,c,d
add,sub,mul,div=calc(20)
print("Sum:",add)
print("Subtraction:",sub)
print("multiplication:",mul)
print("Division:",div)

Practical 8: inbuild date functions:


import datetime
dt=datetime.datetime.now()
print("Today's date:",dt)
print("Today's date:",dt.date())
days=["Mon","Tuesday","Wednesday"]
print("Today's weekday:",dt.weekday())
print("Today's weekday:",days[dt.weekday()])
print("Time:",dt.time())

Practical 9: inbuild math and random functions:


import random
import math
print(eval('45*6'))

2
print(eval('(45*6)-(12/3)'))
print(max(45,23,41,89,45,23,))
print(max('Apple','Bombay','Mumbai'))
print(min(45,23,41,89,45,23,))
print(min('Apple','Bombay','Mumbai'))
print(pow(2,3))
print(round(3.1416))
print(round(3.1456,2))
print(int('12')+int('12'))
print(round(random.random()*10))
print(random.choice([1,2,3,4,5]))
print(random.randrange(1,6,3))
print(math.ceil(12.5))
print(math.floor(12.5))
print(math.sqrt(36))

You might also like