0% found this document useful (0 votes)
19 views21 pages

Week 14 2024bes 123 Topic 12 17 Predefined Functions Statement

Computer programming Module for 2nd year College for free

Uploaded by

tolorioleodimar2
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)
19 views21 pages

Week 14 2024bes 123 Topic 12 17 Predefined Functions Statement

Computer programming Module for 2nd year College for free

Uploaded by

tolorioleodimar2
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
You are on page 1/ 21

WMSU

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

At the end of this section, you should be able to:

1. Use predefined function(s) in a program


2. Create your own function
3. Write programs in modular approach
4. Use different types of parameters in a function

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!

Why is enrolment process divided into steps?


Answer: It was divided into 5 steps, to have a better flow of
enrollment process.
If only one person is in-charge for the entire enrolment process, will the
enrolment become faster? Will the enrolment process have lesser error?
Answer: DEFINITELY NO specially for a University Like WMSU, it’s a
big school to accommodated thousands of students enrolled.

Answer: DEFINITELY NO it will cause a delay

9
Read and Ponder!
FUNCTION

• A function is a subprogram that is executed


when it is called from some point of the program,
it will not be executed unless it is called. The
statement used to execute a function is called the
function call.

• A function call is an expression consisting of the


function name followed by the arguments
enclosed in parenthesis. 10
Read and Ponder!
FUNCTION

One of the advantages of using functions to divide


programming task into subtasks is that different
people can work on different subtasks. Also, it is
easier to debug a program with lesser lines of codes
compared to a huge program.

There are two types of functions two namely:


1. Pre-defined function
2. Programmer Defined Function
11
Read and Ponder!
Predefined Function

Python comes with libraries of Predefined functions that


you can use in your program. These Predefined functions
are ready made function and has already been defined.

For more Predefined functions please proceed to this link


https://docs.python.org/3/library/functions.html

12
Read and Ponder!
Predefined Function
Built-in Modules in Python

• The Python interpreter has a number of built-in


functions. They are loaded automatically as the
interpreter starts and are always available.

• For example, print() and input() for I/O, number


conversion functions int(), float(), complex(), data
type conversions list(), tuple(), set(), etc.
13
Read and Ponder!
Predefined Function
Built-in Modules in Python
• In addition to built-in functions, a large number of
pre-defined functions are also available as a part
of libraries bundled with Python distributions.

• These functions are defined in modules.

14
Read and Ponder!
Python - Math Module

• Some of the most popular mathematical functions are


defined in the math module. These include
trigonometric functions, representation functions,
logarithmic functions, angle conversion functions, etc.

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

Another well-known mathematical constant defined in the


math module is e. It is called Euler's number and it is a
base of the natural logarithm. Its value is
2.718281828459045.

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")

print("HYPOTENUSE OF THE TRIANGLE")


A=float(input(" ENTER the value of A="))
B=float(input(" ENTER the value of B="))
Hypotenuse= math.sqrt((A**2)+(B**2))
print("The Hypotenuse of the triangle is=", Hypotenuse, "unit(s)")

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

You might also like