Illustration for 🎯 What Is a Function?

What Is a Function?

The secret “recipe” that makes computers do cool tricks!


Imagine you have a magic box that can turn a list of numbers into a new list, or draw a picture whenever you ask it. In computer science we call that magic box a Function. A function is a tiny program inside a bigger program that takes some input, does something with it, and gives back an output. Let’s explore how functions work, why they’re useful, and how you can try them out yourself!


1. The Basics: Input, Output, and the “black Box” 🎁

TermWhat It MeansKid‑Friendly Example
InputThe data you give the function.Giving a recipe the ingredients you have.
OutputWhat the function sends back after it works.The tasty cake you get after baking.
Black BoxWe don’t need to see inside; we just know what goes in and what comes out.A vending machine: you insert money (input) and get a snack (output).

Cause And Effect:

  • Cause: You give the function the number 5.
  • Effect: The function adds 2 and returns 7.

2. Why Do We Use Functions?

  1. Reuse – Write the code once, use it many times.
  2. Organization – Break a big problem into smaller, manageable pieces.
  3. Abstraction – Hide the complicated steps, so you can think about the big picture.

Did you know? The word Abstraction comes from the Latin “abstrahere,” meaning “to pull away.” In programming it means pulling away the details you don’t need to see right now.


3. Parts of a Function

A typical function looks like this (in a language called Python):

def add_two(number):          # ← function name and its *parameter*
    result = number + 2       # ← the *body* – what the function does
    return result             # ← the *return value* (output)
  • Def – short for define; tells the computer we’re creating a new function.
  • Add_two – the Function Name; like a label on the magic box.
  • Parameter – the placeholder for the input (here, number).
  • Return – the command that sends the output back to the caller.

Cause And Effect In This Example:

  • Cause: Call add_two(10).
  • Effect: The function calculates 10 + 2 and returns

Continue the adventure

Download Surprise Button for iPad

A simple, safe way for kids to explore the internet. With one tap, they discover something new — a fun fact, a science experiment, a story, or a place in the world they never would've searched for.

Download on the App Store

Your child explores safely on Surprise Button App

🌋

How Volcanoes Form

From Magma to Mountain

Volcanoes grow where tectonic plates collide or drift apart. Heat melts rock into light, buoyant magma that rises, cools, and hardens near the surface, building the cone layer by layer.

Know exactly what to talk about tonight

Maya's Daily Discoveries - March 15 Inbox

🚀 Today's Learning Journey

🌋
How Volcanoes Form
18 min • Longest session today
🎨
Ancient Egyptian Art
15 min • Visited twice today

💬 Tonight's Conversation Starters

"Can you explain how volcanoes form?"