Week 14 2024bes 123 Topic 12 17 Predefined Functions Statement
Week 14 2024bes 123 Topic 12 17 Predefined Functions Statement
Prepared By:
DR. FHELDAURA T. ABUBAKAR
1
FUNCTIONS
2
Read and Ponder!
Introduction to Functions
• After completing the previous sections, you are now equipped with
the basics of Python programming. You know that programs are
created to solve problems. So far, you only created small programs
that solve a specific problem.
• However, most of the programs such as websites or games
composed of smaller programs that are joined and integrated to
create one huge application. It sounds complicated, right? And
maybe you can already imagine thousands lines of codes.
• In most cases, these huge applications are divided into chunks for
easy programming and management not just by a single
programmer but also for a group of programmers. How? Well,
easy… functions! 3
Read and Ponder!
Introduction to Functions
• Let’s take a look at your own television sets. Do you know how
televisions are manufactured? Production of television consists of
several lines (of production) and each line is assigned for a special
task. At the end of each production line, outputs are being checked
before proceeding to the next production line. This is done to
assure that the unit is functional.
• In programming, you can also create programs chunk by chunk.
Each chunk is a part of a huge program. Each chunk is being tested
of its functionality before embedding to the huge program. These
chunks are called functions. This programming technique is called
the modular approach. 4
Objectives:
Introduction to Functions
5
Topic Outline:
Introduction to Functions
1. Introduction to Functions
2. Pre-defined Functions
3. Programmer defined Functions
4. Types of parameters
6
Try This!
During enrolment, after filling up the red form, how many steps
have you undergone before getting officially enrolled?
FOR ONLINE:
1. pre-registration in the form of google docs, link thru facebook.
2. Interview via phone call from your chosen course
3. Acknowledgement/consent from the students via google
docs.
4. Confirmation email coming from the university technical
person that you are already accepted by your chosen course.
5. Officially enrolled.
7
Try This!
During enrolment, after filling up the red form, how many steps
have you undergone before getting officially enrolled?
1. SIGNATURES OF ADVISERS/ REGISTRARS(DH)
2. ENCODING
3. ASSESSMENT
4. PAYMENT (CASHIER)
5. COR (CERTIFICATE OF ENROLLMENT)
6. OFFICIALLY ENROLLED (SURRENDERED RED
FORM TO THE DEPT)
8
Think Ahead!
9
Read and Ponder!
FUNCTION
12
Read and Ponder!
Predefined Function
Built-in Modules in Python
14
Read and Ponder!
Python - Math Module
15
Read and Ponder!
Python - Math Module
• Some of the functions includes log(), exp(), pow(),
sqrt(), ceil() and floor().
• In addition, two mathematical constants are also
defined in this module.
• Pie (π). Here, you will be able to enhance your previous
programs by implementing variable) is a well-known
mathematical constant, which is defined as the ratio of
the circumference to the diameter of a circle and its
value is 3.141592653589793. 16
Read and Ponder!
Python - Math Module
17
Read and Ponder!
SAMPLE PROGRAM
18
Read and Ponder!
SAMPLE PROGRAM
#HYPOTENUSE OF THE TRIANGLE
#PYTHAGOREAN THEOREM
#h=sqrt(a,2+b,2)
import math
print("YOUR NAME")
print("YOUR COURSE AND SECTION")
19
Read and Ponder!
SIMULATION
YOUR NAME
YOUR COURSE AND SECTION
HYPOTENUSE OF THE TRIANGLE
ENTER the value of A=3.2
ENTER the value of B=5.7
The Hypotenuse of the triangle is= 6.536818798161687 unit(s)
20
21