You are on page 1of 19

LAB MODULE A

Coding & Big Data

Part 7
Function in Python
What is Function?

How to create a function?

Outline Practice I

Arguments

Practice II

Return

Practice III

Submission
What is Function is a block of code that will
be run if it is called.
Function? A function is a block of organized, reusable
code that is used to perform a single, related
action. Functions provide better modularity
for your application and a high degree of
code reusing.
Function
How to create a function?
Code
Output

Function in python will always start with def


Can I change the function name? Sure! Change your function name as you wish
Don’t forget, after you named the function, you have to add parantheses ( () )
Practice I
For student whose last For student whose last
digit of student id is digit of student id is even
odd
Recreate previous program, create a function Recreate previous program, create a function name
name helloMe, and the output will be Hello, helloYou, and the output will be Hello, your student ID
your name
Arguments
What is arguments?
Code
Output

Arguments means we are giving an information into the function.


Don’t forget to initialize the function to receive parameters when called.
You can pass as much arguments as you like!
Practice II:
For student whose last For student whose last
digit of student id is digit of student id is even
odd
Recreate previous program, create a function Recreate previous program, create a function name
name helloYou, pass your student ID as the helloMe, pass your name as the arguments, and the
arguments, and the output will be Hello, your output will be Hello, your name
student ID
Return
What is return?
Code
Output

Return means a function is giving back the result to the caller


Practice III:
For student whose last For student whose last
digit of student id is digit of student id is even
odd
Recreate previous program, create a function, Recreate previous program, create a function, the name
the name is up to you. The function will
is up to you. The function will divide two values that
multiply two values that you pass as the you pass as the arguments. You have to use return to
arguments. You have to use return to obtain the obtain the result
result
Submission
Screenshot & Upload to eCampus
Screenshot your codes and terminals, put them into docx or pdf file. Don’t forget to put your name and
student ID in the top of the file. Upload the file to eCampus on Practice Week 7 before Friday.

Practice I  Screenshot your program code and output depending on your student ID last digit

Practice II Screenshot your program code and output depending on your student ID last digit

Practice III  Screenshot your program code and output depending on your student ID last digit
Questions?
References
Python Functions

You might also like