← Computer Studies / 3 Software development

3.6 Functions

Computer Studies · Grade 10 · 14 lessons in the design

What this covers

  • Modular programming and its importance
  • Built-in and user-defined functions
  • The syntax of a function: name, parameters, body, return value
  • Parameter passing: formal and actual parameters, return values
  • The scope of variables: local and global
  • The role of functions in programming

What you will be able to do

  • discuss the types of function used in modular programming
  • use built-in and user-defined functions to create a modular program
  • discuss the scope of variables and parameter passing between functions

Key questions

“What are the roles of functions in programming?”

Lessons

The titles are open to everyone. Reading a lesson needs an account — sign in or create one.

  1. Functions and modular programming
    40 min · 1 practice tasks · quiz
    What a function is, built-in versus user-defined, how to define and call one, and why breaking a program into functions is how all real software is built.
  2. Parameter passing and variable scope
    40 min · 1 practice tasks · quiz
    How functions communicate through parameters and return values, and how local and global scope keep the parts of a program from interfering.
  3. Why modular programming
    40 min · 1 practice tasks · quiz
    A kiosk till as one tangled script versus named functions - why real software is built in pieces.
  4. Built-in functions in practice
    40 min · 1 practice tasks · quiz
    print, input, int, len, range, min, max, sum, type - ready-made tools, and why the language ships them.
  5. Writing a function definition
    40 min · 1 practice tasks · quiz
    def, a meaningful name, colon, indented body - define greet once, then call it.
  6. Parameters: giving a function data
    40 min · 1 practice tasks · quiz
    Zero, one or several parameters. Matched left to right. A VAT function that takes a price.
  7. Return values: getting a result back
    40 min · 1 practice tasks · quiz
    return hands a value to the caller. print only shows a human. Catch the result in a variable.
  8. Functions calling functions
    40 min · 1 practice tasks · quiz
    A final_bill that asks subtotal and add_vat to work - composition, and testing one piece at a time.
  9. Formal and actual parameters
    40 min · 1 practice tasks · quiz
    length and width are formal; 5 and 3 are actual. The signature is the contract the caller must keep.
  10. Local variables in practice
    40 min · 1 practice tasks · quiz
    Each call gets a fresh private total. When the function ends, the local name is gone.
  11. Global variables and constants
    40 min · 1 practice tasks · quiz
    A name outside every function is global. Use it sparingly, mainly for true constants such as VAT 0.16.
  12. Value-returning and void functions
    40 min · 1 practice tasks · quiz
    Some functions compute a result; some only do a job such as printing a receipt. Know which you are writing.
  13. Building a modular program
    40 min · 1 practice tasks · quiz
    A school-mark reporter from small functions: input, average, grade, report - the 3.6 outcome in one sitting.
  14. The roles of functions
    40 min · 1 practice tasks · quiz
    Reuse, simplicity, easier fixes, teamwork, readability - and abstraction as the idea underneath all five.