Function Calculator

Function Calculator

# Functions

### What is a Function?

Think of functions like a vending machine. When you enter in a code, you get a soda. Same with a function, when you enter in an input number, you get an output number. Try it out!

big red
A1
incakola
A2
yakult
A3
kuat
A4
sprite
A5
big red
B1
incakola
B2
yakult
B3
kuat
B4
sprite
B5
big red
C1
incakola
C2
yakult
C3
kuat
C4
sprite
C5
big red
D1
incakola
D2
yakult
D3
kuat
D4
sprite
D5
1
1
4
2
9
3
16
4
25
5
1
-1
4
-2
9
-3
16
-4
25
-5
36
6
49
7
64
8
81
9
100
10
36
-6
49
-7
64
-8
81
-9
100
-10

Just like a vending machine maps inputs to outputs, a function is a mapping between a set of inputs and a set of outputs.

### Function Rules

Notice a couple things:

1. A function (or vending machine) take in an input and returns an output.
2. Every input has only ONE output - when you input A1, you only get Big Red, nothing else. And when you input 3, you only get 9, nothing else.
3. Multiple inputs can have the same output. To get Inca Kola, you can put in A2, B2, or C2. And to get 9, you can input 3 or -3.
4. Every possible input on our keypad has an output. There are some numbers/codes that aren't on our keypads, like E1 or -15, but that's okay. We define a set of inputs, like our keypad, and we just need to make sure every input is covered.

### Function Examples

In non-vending machine language, we write functions as something like

We represent our input with a variable, like , and our output is a calculation that uses our input, or variable. So, something like this:

So, when we input 2, all our 's are replaced with 2, and our output comes out to be 11:

Just like our vending machines!