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 then amend so that it adds a message after "howdy" that says well done on reaching the age........

3) Write a new procedure that takes the name and outputs the name all in capitals then all in lower case then the first letter and the last letter of the name. 

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

Help with String Methods 

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