Python/🐍 Python Foundations/Functions

Functions

Functions are defined with def keyword. They can take parameters, have default values, and return results. Python supports *args and **kwargs.

Guided Example

# Example: Function with default parameter
def greet(name, greeting="Hello"):
    return f"{greeting}, {name}!"

print(greet("Alice"))
print(greet("Bob", "Hi"))

Practice Problems (0/3 solved)

Easy

Maximum of Three

Write a function max_of_three(a, b, c) that returns the largest of three numbers. Test with max_of_three(3, 7, 5) and print the result.

Loading Python...
Loading...

Loading Python runtime (Pyodide)...

Medium

Palindrome Check

Write a function is_palindrome(s) that returns True if s reads the same forwards and backwards (case-insensitive). Test with "Racecar" and print the result.

Loading Python...
Loading...

Loading Python runtime (Pyodide)...

Medium

Factorial

Write a recursive function factorial(n) that computes n!. Print factorial(6).

Loading Python...
Loading...

Loading Python runtime (Pyodide)...