Professional Documents
Culture Documents
Oop Using Python Unit-2.5 Functions-1
Oop Using Python Unit-2.5 Functions-1
Madana Mohana
FUNCTIONS-1:
Introduction
Function Definition
Function Call
https://www.youtube.com/c/RASINENIMADANAMOHANA
Introduction
Function Definition
Example Programs
Functions: Introduction
A collection of statements together into a single
unit. This unit is called a function.
In Python, function is a group of related
statements that perform a specific task.
If a group of statements is repeatedly required
then it is not recommended to write these
statements every time separately.
Functions: Introduction
We have to define these statements as a single unit
and we can call that unit any number of times
based on our requirement without rewriting. This
unit is nothing but function.
A function is a block of code which only runs when
it is called.
You can pass data, known as parameters, into a
function.
A function can return data as a result.
Advantages/Need of Python Functions
OUTPUT:
30
15
40
FUNCTIONS - Example Programs
OUTPUT:
welcome to Python Course
FUNCTIONS - Example Programs
Pgm-3: write multiple functions in a single program
def morning():
print('Good Morning')
def afternoon():
print('Good Afternoon')
def evening():
print('Good Evening')
def night():
print('Good Night')
morning()
afternoon()
evening()
night()
FUNCTIONS - Example Programs
Pgm-3: write multiple functions in a single program
OUTPUT:
Good Morning
Good Afternoon
Good Evening
Good Night
FUNCTIONS - Example Programs
Pgm-4: write a function to find the biggest of two
numbers
def biggest(x,y):
if x>y:
return x
else:
return y
a = int(input("Enter first number:"))
b = int(input("Enter second number:"))
big = biggest(a,b)
print('Biggest number =',big)
FUNCTIONS - Example Programs
Pgm-4: write a function to find the biggest of two
numbers
OUTPUT:
Enter first number20
Enter second number10
Biggest number = 20
Enter first number:20
Enter second number:30
Biggest number = 30