DUA
2
Objectives
◎ Revision
◎ Introduction to Functions
◎ Built in functions vs Self Defined
◎ Calculator with functions
◎ Reflection
◎ Complete the Quiz and Assignment
WIN-WIN AGREEMENT
• -Sign in using your Full Name and type present in the chat
box as soon as you enter.
• -Turn on your video.
• -Use pickers like raising hands or typing in chat box to clear
your queries during or last 5 minutes of your block according
to the teacher’s instructions.
• -Practice the learnt concepts.
• -Attempt the quiz and submit the assignment on time in
Google classroom.
Note: Zoom blocks are recorded
4
What is a function in Python?
• In Python, a function is a group of related statements
that performs a specific task.
• Functions help break our program into smaller and
modular chunks. As our program grows larger and
larger, functions make it more organized and
manageable.
• Furthermore, it avoids repetition and makes the code
reusable.
Built in Functions
input()
reads and returns a line of string
print()
Prints the Given Object
SYNTAX OF A USER DEFINED
FUNCTION
Name of function Optional Parameters
Keyword to start
function definition
Colon to mark end of
def function_name(parameters): function header
"""docstring"""
statement(s)
Statements or code of Description of the
the function function
Example of a function
def greet(name):
""" This function greets to the person passed in as a parameter """
print("Hello, " + name + ". Good morning!")
How to use a function
greet('Paul’)
Addition Function
def add_function(num1, num2):
num3 = num1 + num2
return num3
A = 50
B = 25
C = add_function(A,B)
print(C)