Functions are like having helpful assistants that do specific jobs for you! Instead of writing the same code over and over, you create a function once and call it whenever you need it. Think of it like a recipe - you write it once, but you can cook the dish many times. Functions make your code organized, reusable, and way less repetitive!
# Create a simple function
def greet_user(name):
print(f"Hello, {name}! Welcome to Python!")
# Use (call) your function
greet_user("Alex")
greet_user("Sam")
# Function that returns a value
def add_numbers(a, b):
result = a + b
return result
sum_result = add_numbers(5, 3)
print("Sum is:", sum_result)
Create a function called 'square_number' that takes a number and returns its square. Then test it with a few different numbers!