CODE PATH
PRO ACCOUNT

Master Code
On The Go

Learn. Practice. Build.

Quest 1 • Lesson 6

📞 Functions

A function is a reusable block of code that performs a specific task. You define it once and call it many times. Functions help you avoid repetition and organise your code better.

"Functions are like recipes – you write the steps once, then you can follow them whenever you need the result."
function_basic.py
def greet():
    print("Hello, world!")

# Call the function
greet()

🧠 Function Basics

function_parameters.py
def greet_person(name):
    print(f"Hello, {name}!")

greet_person("Alice") # Output: Hello, Alice!
function_return.py
def add(a, b):
    return a + b

result = add(5, 3)
print(result) # Output: 8

📤 Return Values

✨ Challenge: Create a Multiplication Function

Write a function multiply(a, b) that returns the product of two numbers. Then call it with 4 and 7, and print the result.

def multiply(a, b):
    return a * b

result = multiply(4, 7)
print(result)  # 28

✨ Bonus Challenge: Celsius to Fahrenheit

Define a function celsius_to_fahrenheit(celsius) that returns the temperature in Fahrenheit. Formula: F = C × 9/5 + 32. Test it with 0 and 100.

❤️ Support Free Education

This course is 100% free. If it helps you, consider buying me a coffee.

☕ Buy Me a Coffee

➡️ Ready for more?

Next lesson: String Methods & Formatting.

Continue to Lesson 1.7 →

(Coming soon – check back or buy Pro Pack for instant access)