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 Repl.it to run your programs on-line.
Here is a reminder of the commands you might need for this assignment.
def function_name() - defines a function or procedure. function_name must be unique within the program, and can't be the name of an existing Python function or procedure (e.g. len or print). You can include one or more arguments inside the brackets and use its value inside the function or procedure, e.g. defining a function as follows and calling double(3) will return 6.
return x * 2
return - sends back a value from a function (it is not needed for a procedure); this can be a fixed value or the result of a calculation.
you can call a procedure just using its name like a command - e.g. if you define a procedure using def hello(): at the top of the program, you run it by adding the command hello() to the main body of your program.
If you would prefer a longer explanation, I have written an article for Computing teachers in the TES called Creating a function - odd or even?
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:
create a function that tests a number for a particular property, e.g. whether it is:
Anything that you're comfortable with, really!
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.