List 6 - Exercises on Functions
1. Write a function with no parameters that prints “Welcome to Python
Functions”.
2. Write a function with one optional parameter name (default “Student”)
that prints “Hello, <name>”.
3. Write a function multiply(x, y) that returns the product of two numbers. Call it with positional and named arguments.
4. Write a function divide and remainder(x, y) that returns both the
quotient and the remainder. Test it with x=20, y=6.
5. Write a function square list(numbers) that returns a new list with
the squares of the elements. Test it with [2, 5, 7].
6. Write a function is even(n) that returns True if the number is even,
False otherwise. Test it with 10 and 13.
7. Demonstrate local vs global scope: define a global variable a=3, b=4,
and a function sum numbers(x, y) that returns their sum. Show that
local variables inside the function do not affect global ones.
1