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

Funky Functions

What am I Learning today?

I am learning how to use simple functions in order to reuse lines of code
I am learning how to use functions with parameters

Knowledge Organiser

×

Lesson

Task 0 - Portait images Click to see more

If you don't yet have a portrait image .

Then save one of the images below image into your adventure folder


  • Save your image as character.Gif into your text adventure folder

  • Task 1 - Code so far Click to see more

    Below is the code we have completed so far check yours against the code below and fill in any gaps



    Task 2 - Understanding Functions Click to see more

    Coding functions

    In computer science, a function is a programming structure that can be used over and over again. We are going to look at a simple Function that prints a greeting.


    Task: A simple function

  • Open Python Thonny
  • Save your file as 'a simple function'


  • Copy the code from the image above and run it.
  • Then choose one of the three challenges below to complete.
    1. Can you put a loop in your simple Function so it prints out your greeting 3 times
    2. Change the function so it asks the user a question then prints out a response
    3. Change the function so that it repeatedly asks the user a question until it gets a specific answer.

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


  • Passing an argument

    Wouldn't it be good if we could give some text to our function so it could used to print out a different greeting each time?

    Task: Passing a value

  • Copy the code below


    1. Add some code to line 6 to allow the user to input their username
    2. Now call the function on line 10 to print out the greeting

    Don't forget to pass the 'username' to the function

    1. Can you ask for another input, age, then add that to the function greeting?

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


  • Returning a value

    One of the main reasons functions are used are to do some calculations then return the answer

    Task: Returning a value

  • Copy the code below and run it to make sure it works:


  • Notice how we use the variable sum to store the value we get back from our function

    1. Get the user to enter the two values then OUTPUT the result.
    1. Can you add three numbers and print out the total

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


  • Task 3 - Asking a question Click to see more

    Have a look at my code below.



    My Notes: Text_Programming

    Student_Comment_2 not found

    Task Notes/Comments - Add here Click to see more

    Comments/Notes