Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
33 views

Functions - Python

An introduction to functions in Python.

Uploaded by

armbennett
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Functions - Python

An introduction to functions in Python.

Uploaded by

armbennett
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Python

Functions
Functions
When programming we will often need to perform a specific task
several times, at different points in the program, this is when functions
come in handy.
A function is a portion of code within a larger program that usually
does something very specific.
Functions in flowcharts are represented using this symbol:
Example 1: Flowchart
Design and code a
program that asks the
user to input two
numbers and uses a
function to compare the
numbers and output the
largest number.
Start
End
COMPARE
INPUT Num1
INPUT Num2
Example 1: Flowchart
Design and code a
program that asks the
user to input two
numbers and uses a
function to compare the
numbers and output the
largest number.
Sub COMPARE
End COMPARE
OUTPUT num2
Is num1
> num2?
OUTPUT num1
Yes
Yes
Is num1
< num2?
No
OUTPUT They
are equal
No
Example 1
Here is part of the solution to the problem, you need to complete it.
Comment your code, explaining what each bit does.
Returning a Value
You can also return a value from a function.
In this example the width and height of a rectangle are passed to a
function, the area is then calculated and returned.
Returns the value in area variable
Prints the returned value
to the screen.

You might also like