Minu's Games logo
MINU'S ROBOTICS

A Minu's Games EdTech Lab

← Code & Cognition
Day 13 of 30Logic & Data Structures

🧩Functions

🎯 Today's objective

Package reusable logic into named functions.

📖 Key concepts

  • def name(params): defines a function
  • return sends a value back
  • Functions avoid repetition (DRY)
  • Call with name(args)

💻 Try this code

def greet(name):
    return f"Hello, {name}!"

def area(w, h):
    return w * h

print(greet("AI"))
print("Area:", area(4, 5))

👥 Learn it your way

🧒 Young Explorers

A function is a magic spell you name once and reuse forever.

Your task

Write is_even(n) that returns True/False, and use it on 5 numbers.

💼 Professionals

Keep functions small and single-purpose; name them as verbs; return rather than print.

Your task

Write celsius_to_f(c) and f_to_celsius(f); verify they round-trip a value.

🤖 AI connection

A trained model is basically a function: give it input (features), it returns output (a prediction). model.predict(x) is just a function call.

✅ Quick check

What does return do?

Sends a value back to whoever called the function.

Why use functions?

Reuse, clarity, and avoiding repeated code (DRY).