Computing
Computer Science LearnITWithMrC ⛯ Year 7 Year 8 Year 9 GCSE
Responsive image

Lesson Video

29

Lesson Tasks

  • Watch the Lesson video
    Make notes if needed.
  • Open your Learning Journal
    Complete Task 1 in your Learning Journal
  • Complete the learning activities
    Make sure you complete the book tasks in your Unit Booklet
  • Complete End of Task Assessment
    Update your learning objectives

What do I need to Learn?

0 results forGuest
I need to learn how to use subroutines that return values to the calling routine.
I need to learn how to use local variables in a subroutine and understand that local variables only exist while the subroutine is executing.
I need to learn how to explain why it is good practice to use local variables

Key Terms

Function Procedure Subroutines Identifier Parameters return value scope

Task 1 - Getting organised Click to see more


Task: Learning Journal

Open your Learning Journal by clicking on the image below

Good notes will help you organise and process data and information

Task 1: Fill out your learning Journal.

Open your Learning Journal and complete the task below .


Task 2 - Subroutines as Functions Click to see more


  • Let's look at an example of using subroutines as a Function:


  • Here the main program (shown in the flowchart above on the left, beginning with the word “Start”) asks the user to input two numbers. It then asks them to select an option from a menu. If they enter the word “add”, it will run a subroutine called addNum (The smaller flowchart on the top right), if they enter anything else it will run the subtractNum subroutine (bottom right).

  • Let's look at the subroutine box in the main flowchart first:


  • We can see the name of the subroutine has been defined along with the variables; num1 and num2. This means that the addNum subroutine is going to use the values of num1 and num2 and so has been passed these values.

  • We can now look at the addNum subroutine flowchart.


  • This subroutine will add together the num1 and num2 variables and store these in a new variable called answer. It will then return the variable answer back to the main menu. It will then go back to the main menu, once the addNum subroutine has been completed, where it will be able to display the answer variable. If we had not returned the answer variable back to the main menu, it would not be able to display the answer in the output as the main program on its own has not defined the answer variable and it does not know what it is.

    Task: Using Functions

    1. Write a function in python for the addNum and subtractNum subroutines.
    2. Use the Flowchart above (also on page 29 of your workbook) to help you write the main program in python with the menu option, so that we can then ask the user which of the options they would like to use and then call the appropriate functions addNum and subtractNum and return the appropriate answer.

  • When you are finished screenshot your code into your Learning Journal


  • Task 3 - Returning Multiple Values Click to see more

    Task: Using Functions to return multiple values

    We have seen that we can use functions to return a single value to our calling routine. But it is also possible to return multiple values from our function, see psuedocode example below:


    1. Turn the Pseudocode above (also on page 32 of your workbook) into a function in python that returns three valuesnum1, num2 and total and then prints out those values .

    Task 4 - Global and Local variables Click to see more

    Key word - Global Variable

    A Global Variable is a variable that is declared in the main program


    Key word - Local Variable

    A Local Variable is a variable that is declared and only used in a subroutine


    Task: Understanding Local Variables

    Open your student workbook at page 33 read through the notes and then answer the questions in your PowerPoint.



    Task 5 - Book Tasks Click to see more

    Task: More Functions

    Open your student workbook at page 35 and complete the following tasks.
    1. Task 16
    2. Task 17
    3. Task 18
    4. Task 19


    Task 6 - End of Chapter Recap Click to see more

    Task: Recap

    Open your student workbook at page 39 and complete Task 20 the end of chapter recap exercise.


    Task 7 - Lesson Review/Homework Click to see more


    Summing it all up

    Lets look at the learning outcomes and decide which one best describes our current level of understanding :

    Tick the one you feel is closest to your level

    Learning Outcomes

    • I have a basic understanding of how with a little help from my teacher
    • I can show my teacher that without their help.
    • independently and I can also explain it to others and can complete any extension tasks I am given.

    🠜 Now update your learning objectivesClick on the Assessment image


    Task 8 - End of Task Assessment Click to see more

    Extension Coding activities

    Function tasks
    Click on the button below and complete as many exercises as you can

    Exercises