Computer Science Essentials, Unit 3, Lesson 1 of 5

Writing functions

GCSE Computer Science, Writing code, 30 minutes

Sign in

How a code question is marked, writing a function that returns a value, selection and loops inside functions, and turning OCR or AQA pseudocode into Python.

What you will learn

  • Write a function with the exact name and parameters asked for
  • Return a value rather than print it
  • Use selection and loops inside a function
  • Translate a pseudocode function into Python

How these questions are marked

In this unit you write real Python in the editor, and it runs against tests.

The tests are shown with the question: they are the task, so read them before you start.

  • A call test runs one line such as area(3, 4) and checks what your function returns.
  • An input test types some lines into your program and checks exactly what it prints.
  • Your mark is your share of the tests passed: pass 3 of 4 tests on a 4-mark question and you score 3.

Use the exact function name and parameters in the question. A function called Area will not be found by a test that calls area.

On paper a marker reads your code against a mark scheme; here the tests do the same job, and the scheme under each question shows what the marks are for.

The rest of this lesson and its 9 practice questions are locked.

In this lesson

  1. How these questions are marked
  2. Return, not print
  3. Loops inside functions
  4. From pseudocode to Python
  5. Try it: Your first function

9 practice questions, marked as you go; about 30 minutes in all.

Key terms

Tests, Call test, Input test, Function, Factor

In this unit: Writing code

Write real Python that runs against tests: functions, validation and logins, strings, lists and 2D lists, records, and completing and refining a program.

All of Writing code