#programming #KK8 [[Outcome 1 - Programming#8. features of a programming language, including| U3 - AOS1 - KK8]] ## What is a function? A function holds a piece of code that does a specific task. A function takes some data as *input*, the code inside the function does something with the data, and then the result is *returned*. Functions are defined by a name, may have *parameters* and may *return* a value. The main idea behind functions is to take a large program, break it into smaller, more manageable pieces (or functions), each of which accomplishes a specific task. ![[image.jpeg]] Below is how the python code looks like for the covertToCelsius function: ```python def convertToCelsius (fahrenheit): celsius = (fahrenheit - 32) * 5 / 9 return celsius ``` ```psuedocode Begin ConvertToCelsius (fahrenheit) celsius <- (fahrenheit - 32) * 5 / 9 Return celsius End CovertToCelsius ``` The function above takes a temperature in Fahrenheit as input, converts it into Celsius, and returns the Celsius value as output. ## VCAA definition While in python and many programming languages functions are not required to return a value VCAA definition of a function is as follows: a **function** is a reusable block of code designed to perform a specific task that take inputs, called parameters, process them, and returns an output value