Functions
Class 11 · Computer Science
4 ideas in Class 11 Computer Science, explained in plain words, with games and quizzes to practise.
Defining Functions
Part of: Function Basics
Functions group steps under names; defined once, called often; parameters take input, return gives back.
Why it matters. Reuse code. Names group work.
Key words
- Function
- : A named block of steps defined once and reused.
- Parameter
- : A named input a function receives when called.
- Return value
- : The result a function hands back to its caller.
- Function call
- : Running a function by writing its name.
Try it in two minutes
- Define the block.
- Pass inputs.
- Return result.
Try at home. Define add block.
Arguments and Return
Part of: Function Basics
Positional, default, keyword arguments pass values; return sends results; void blocks return none.
Why it matters. Values passed flexibly. Results returned.
Key words
- Positional argument
- : Values matched to parameters by position.
- Default argument
- : A fallback value used when the caller sends none.
- Keyword argument
- : A value matched by writing the parameter name.
- Return statement
- : The line that ends a function and sends a result back.
Try it in two minutes
- Pass positionally.
- Default some.
- Return result.
Try at home. Call with defaults.
Variable Scope
Part of: Scope and Recursion
Local lives inside blocks; global lives everywhere; same names shadow; global keyword shares.
Why it matters. Reach known. Clashes avoided.
Formulas
- A name assigned inside a block stays local unless declared global
Key words
- Local variable
- : A variable usable only inside its own block.
- Global variable
- : A variable visible throughout the program.
- Name shadowing
- : A local name hiding an outer name of the same spelling.
- Global keyword
- : The declaration sharing a global inside a block.
Try it in two minutes
- Inside or outside?
- Shadow checked?
- Share if needed?
Try at home. Shadow a name.
Recursion and Libraries
Part of: Scope and Recursion
Recursion calls self with smaller pieces; base case stops; math blocks give sqrt, power ready-made.
Why it matters. Self-calls solve. Libraries save.
Formulas
- Every recursion needs a base case and a smaller self-call
Key words
- Recursion
- : Solving a problem by calling the same function smaller.
- Base case
- : The stopping case that ends the self-calls.
- Self-call
- : A call to the same function with shrunken input.
- Math module
- : Ready-made blocks for square root, power and more.
Try it in two minutes
- Base case?
- Smaller call?
- Import library?
Try at home. Trace factorial four.
What your child will practise
- Arguments and Return: Ocean Puzzle (Clue Puzzle)
- Arguments and Return: Ocean Quick Fire (Quick Fire)
- Defining Functions: Jungle Puzzle (Clue Puzzle)
- Recursion and Libraries: Ocean Quest (Flip and Match)
- Variable Scope: Desert Quick Fire (Quick Fire)
- Quiz: Arguments and Return (8 questions)
- Quiz: Defining Functions (8 questions)
- Quiz: Recursion and Libraries (8 questions)
- Quiz: Variable Scope (8 questions)