Sub Procedures Passing Parameters

A sub procedure is a separate piece of code that can be run many times from within your main program. 

If you have been using the main()  then you have been running the main procedure. 

You may have used procedures in your code so far and that is good - it is good practice to split up your code into procedures.  

Functions and Procedures 

A procedure should do a task for you such as output a message etc.  A value is not usually returned from a procedure. 

A Function usually does something like a calculation or a selection and returns a result to the program 

In Python a sub routine is defined using the keyword def 

See the examples below 

You can use this code to output names using a parameter.  See this code below.

The output looks like this. 

Challenge 

1) Can you amend this program to allow the user to enter their name then use the procedure to output a message for them.

2) Amend the procedure called outputMyMessage so that it also takes an age as a parameter then amend so that it adds a message after "howdy" that says well done on reaching the age........

-----------------------------------------------------

Other info - You can add a default parameter to the design of a procedure. 

If you call the procedure without a parameter  outputMyMessage():  then it will put Dave in.