# Python:Letters for Numbers Tutorial

Using variables. We must learn how to use variables in expressions.
Just as in algebra we can use letters to represent numbers - they
may be added, subtracted and multiplied.

Operator | Meaning | Expression | value when x is 7 |
---|---|---|---|

`+` | Add | x+3 | 10 |

`-` | Minus | x-3 | 4 |

`*` | Multiply | x*3 | 21 |

`/` | Divide | x/3 | 2 |

`%` | Modulus | x%3 | 1 |

## Twice

The program fragment shown defines a function that doubles it's input. When the program is executed we see the result of the function for a handful of values.

The function definition is embedded in a larger program that is responsible for testing the function at values 1, 2, 3, 4, 5 and 6.

Notice what happens if you change the function so that it multiplies by 3 instead of 2.

[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]

## Half

Change the function so that it returns half the input value. This program only accepts an integer result so we ignore any remainder.

[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]

## Modulus

Change the function so that it returns the remainder when divided by two. For even numbers this is 0, for odd numbers this is 1.

[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]

## Add VAT

Change the function f so that it adds VAT to it's input. VAT is 20%

[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]