Functions and Procedures

Functions and procedures and one of the key ideas of developing larger programs. Some programming languages have different structures and commands for functions and procedures, but in Python they're created in the same way and the only difference is that you don't return a value from a procedure. If you missed the first assignment, click here for instructions on how to install Python. If you are unable to install Python then you can use to run your programs on-line.


Here is a reminder of the commands you might need for this assignment.

If you would prefer a longer explanation, I have written a blog called Creating a function - odd or even?

Your Task

You will already be familiar with built-in functions and procedures such as len() and print(), but today you're going to create your own (you can also do the same thing in Excel if you learn a bit of BASIC). Your program should:

  1. create a function that tests a number for a particular property, e.g. whether it is:
    1. odd or even
    2. square
    3. prime
    4. a palindrome (or has repeated digits)

    Anything that you're comfortable with, really!

  2. display the numbers from 0 to 100, and the result of the test in step 1 (i.e. whether the number is odd/even, square, prime, etc.)

If you can think of a more interesting use for a function, then feel free to program that and submit it instead - just remember to use the Comments box to tell me what it does.